Chromium Code Reviews

Unified Diff: sdk/lib/_internal/pub/lib/src/barback/pub_barback_logger.dart

Issue 26572010: Improve barback/pub logging. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add missing file. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Index: sdk/lib/_internal/pub/lib/src/barback/pub_barback_logger.dart
diff --git a/sdk/lib/_internal/pub/lib/src/barback/pub_barback_logger.dart b/sdk/lib/_internal/pub/lib/src/barback/pub_barback_logger.dart
new file mode 100644
index 0000000000000000000000000000000000000000..374e1581d0e3790885ceb9b11975b028f7e8d7a9
--- /dev/null
+++ b/sdk/lib/_internal/pub/lib/src/barback/pub_barback_logger.dart
@@ -0,0 +1,63 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library pub.pub_barback_logger;
+
+import 'package:barback/barback.dart';
+
+import '../log.dart' as log;
+
+/// A [BarbackLogger] that routes through pub's logging code.
+class PubBarbackLogger implements BarbackLogger {
+ /// Since both [LogEntry] objects and the message itself often redundantly
+ /// show the same context like the file where an error occurred, this tries
+ /// to avoid showing redundant data in the entry.
+ void logEntry(LogEntry entry) {
+ messageMentions(String text) {
+ return entry.message.toLowerCase().contains(text.toLowerCase());
+ }
+
+ var prefixParts = [];
+
+ // Show the level (unless the message mentions it.)
nweiz 2013/10/16 19:41:27 ".)" -> ")."
Bob Nystrom 2013/10/28 23:45:56 Done.
+ if (!messageMentions(entry.level.name)) {
+ prefixParts.add("${entry.level} in");
+ }
+
+ // Show the transformer.
+ prefixParts.add(entry.transform.transformer);
+
+ // Mention the primary input of the transform unless the message seems to.
+ if (!messageMentions(entry.transform.primaryId.path)) {
+ prefixParts.add("on ${entry.transform.primaryId}");
+ }
+
+ // If the relevant asset isn't the primary input, mention it unless the
+ // message already does.
+ if (entry.asset != entry.transform.primaryId &&
+ !messageMentions(entry.asset.path)) {
+ prefixParts.add("with input ${entry.asset}");
+ }
+
+ var prefix = "[${prefixParts.join(' ')}]:";
nweiz 2013/10/16 19:41:27 Minor formatting thing, but it seems weird to have
Bob Nystrom 2013/10/28 23:45:56 I think it helps make it clearer that the prefix i
+ var message = entry.message;
+ if (entry.span != null) {
+ message = entry.span.getLocationMessage(entry.message);
+ }
+
+ switch (entry.level) {
+ case LogLevel.ERROR:
+ log.error("${log.red(prefix)}\n$message");
nweiz 2013/10/16 19:41:27 Use prefixLines to make it clear that the message
Bob Nystrom 2013/10/28 23:45:56 See above. In my manual testing, I thought this fo
nweiz 2013/10/29 00:40:13 I just meant prefixing it with a couple of spaces,
+ break;
+
+ case LogLevel.WARNING:
+ log.warning("${log.yellow(prefix)}\n$message");
+ break;
+
+ case LogLevel.INFO:
+ log.message("$prefix\n$message");
+ break;
+ }
+ }
+}

Powered by Google App Engine