Skip to content

Add colors based on severity #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/src/builder/build_step_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,9 @@ class BuildStepImpl implements BuildStep {
await _resolvers.get(toBarbackTransform(this), [toBarbackAssetId(id)]));

/// Should be called after `build` has completed. This will wait until for
/// [_outputsCompleted] and will also close the [logger].
/// [_outputsCompleted].
Future complete() async {
await _outputsCompleted;
await _logger?.clearListeners();
}

/// Checks that [id] is a valid input, and throws an [InvalidInputException]
Expand Down
4 changes: 3 additions & 1 deletion lib/src/generate/build_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class BuildImpl {
'one of its dependencies. This could be caused by a pub get or '
'any other change. Please terminate the build script and restart '
'it.';
_logger.warning(message);
_logger.severe(message);
return new BuildResult(BuildStatus.Failure, buildType, [],
exception: message);
}
Expand Down Expand Up @@ -135,8 +135,10 @@ class BuildImpl {
new Asset(_assetGraphId, JSON.encode(_assetGraph.serialize()));
await _writer.writeAsString(assetGraphAsset);

_logger.info('Build succeeded');
return result;
} catch (e, s) {
_logger.severe('Build failed: $e\n\n$s');
return new BuildResult(BuildStatus.Failure, buildType, [],
exception: e, stackTrace: s);
} finally {
Expand Down
23 changes: 22 additions & 1 deletion lib/src/generate/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,23 @@ class BuildOptions {
/// Set up logging
logLevel ??= Level.INFO;
Logger.root.level = logLevel;
onLog ??= stdout.writeln;
onLog ??= (LogRecord record) {
var color;
if (record.level < Level.WARNING) {
color = _cyan;
} else if (record.level < Level.SEVERE) {
color = _yellow;
} else {
color = _red;
}
var message = '$color[${record.level}]$_endColor ${record.loggerName}: '
'${record.message}\n';
if (record.level >= Level.SEVERE) {
stderr.write(message);
} else {
stdout.write(message);
}
};
logListener = Logger.root.onRecord.listen(onLog);

/// Set up other defaults.
Expand All @@ -67,3 +83,8 @@ class BuildOptions {
directoryWatcherFactory ??= defaultDirectoryWatcherFactory;
}
}

final _cyan = Platform.isWindows ? '' : '\u001b[36m';
final _yellow = Platform.isWindows ? '' : '\u001b[33m';
final _red = Platform.isWindows ? '' : '\u001b[31m';
final _endColor = Platform.isWindows ? '' : '\u001b[0m';
7 changes: 1 addition & 6 deletions lib/src/generate/watch_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,6 @@ class WatchImpl {
_currentBuild =
_buildImpl.runBuild(validAsOf: validAsOf, updates: updatedInputsCopy);
_currentBuild.then((result) {
if (result.status == BuildStatus.Success) {
_logger.info('Build completed successfully');
} else {
_logger.warning('Build failed');
}
_resultStreamController.add(result);
_currentBuild = null;
if (_nextBuildScheduled) {
Expand All @@ -169,7 +164,7 @@ class WatchImpl {
var watcher = _directoryWatcherFactory(package.location.toFilePath());
watchers.add(watcher);
_allListeners.add(watcher.events.listen((WatchEvent e) {
_logger.fine('Got WatchEvent for path ${e.path}');
_logger.finest('Got WatchEvent for path ${e.path}');
var id = new AssetId(package.name, path.normalize(e.path));
var node = _assetGraph.get(id);
// Short circuit for deletes of nodes that aren't in the graph.
Expand Down
1 change: 0 additions & 1 deletion lib/src/server/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'dart:async';
import 'dart:io';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart';
import 'package:shelf_static/shelf_static.dart';

import '../generate/options.dart';
import '../generate/watch_impl.dart';
Expand Down