Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

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

Issue 48993007: Revise barback logging patch. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/barback/lib/src/utils.dart ('k') | sdk/lib/_internal/pub/lib/src/barback/dart2js_transformer.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/pub/lib/src/barback.dart
diff --git a/sdk/lib/_internal/pub/lib/src/barback.dart b/sdk/lib/_internal/pub/lib/src/barback.dart
index ae6159b9dbfb41b0cd782a228d4876ffe7f73b43..84a069a3f28086e285a145dbb5a8691f8437c6fe 100644
--- a/sdk/lib/_internal/pub/lib/src/barback.dart
+++ b/sdk/lib/_internal/pub/lib/src/barback.dart
@@ -10,10 +10,10 @@ import 'package:barback/barback.dart';
import 'package:path/path.dart' as path;
import 'barback/load_all_transformers.dart';
-import 'barback/pub_barback_logger.dart';
import 'barback/pub_package_provider.dart';
import 'barback/server.dart';
import 'barback/sources.dart';
+import 'log.dart' as log;
import 'package_graph.dart';
import 'utils.dart';
@@ -110,8 +110,9 @@ class TransformerId {
Future<BarbackServer> createServer(String host, int port, PackageGraph graph,
{Iterable<Transformer> builtInTransformers, bool watchForUpdates: true}) {
var provider = new PubPackageProvider(graph);
- var logger = new PubBarbackLogger();
- var barback = new Barback(provider, logger: logger);
+ var barback = new Barback(provider);
+
+ barback.log.listen(_log);
return BarbackServer.bind(host, port, barback, graph.entrypoint.root.name)
.then((server) {
@@ -249,3 +250,56 @@ String idtoUrlPath(String entrypoint, AssetId id) {
throw new FormatException('Cannot access assets from "$dir".');
}
}
+
+/// Log [entry] using Pub's logging infrastructure.
+///
+/// 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 _log(LogEntry entry) {
+ messageMentions(String text) {
+ return entry.message.toLowerCase().contains(text.toLowerCase());
+ }
+
+ var prefixParts = [];
+
+ // Show the level (unless the message mentions it).
+ 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.assetId != entry.transform.primaryId &&
+ !messageMentions(entry.assetId.path)) {
+ prefixParts.add("with input ${entry.assetId}");
+ }
+
+ var prefix = "[${prefixParts.join(' ')}]:";
+ 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");
+ break;
+
+ case LogLevel.WARNING:
+ log.warning("${log.yellow(prefix)}\n$message");
+ break;
+
+ case LogLevel.INFO:
+ log.message("$prefix\n$message");
+ break;
+ }
+}
« no previous file with comments | « pkg/barback/lib/src/utils.dart ('k') | sdk/lib/_internal/pub/lib/src/barback/dart2js_transformer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698