Skip to content

Commit 700ec23

Browse files
committed
info logs now overwrite each other by default
1 parent fe11954 commit 700ec23

File tree

4 files changed

+22
-20
lines changed

4 files changed

+22
-20
lines changed

e2e_example/tool/watch.dart

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,5 @@ main() async {
1717
/// the transitive deps issue.
1818
CopyBuilder.addPhases(phases, graph);
1919

20-
await for (var result in watch(phases)) {
21-
if (result.status == BuildStatus.Success) {
22-
stdout.writeln(result);
23-
} else {
24-
stderr.writeln(result);
25-
}
26-
}
20+
watch(phases);
2721
}

lib/src/generate/build_impl.dart

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class BuildImpl {
6565
{DateTime validAsOf, Map<AssetId, ChangeType> updates}) async {
6666
validAsOf ??= new DateTime.now();
6767
updates ??= <AssetId, ChangeType>{};
68+
var watch = new Stopwatch()..start();
6869

6970
/// Assume incremental, change if necessary.
7071
var buildType = BuildType.Incremental;
@@ -104,13 +105,11 @@ class BuildImpl {
104105
.forEach(
105106
(node) => (node as GeneratedAssetNode).needsUpdate = true);
106107
} else {
107-
var message = 'Build abandoned due to change to the build script or '
108-
'one of its dependencies. This could be caused by a pub get or '
109-
'any other change. Please terminate the build script and restart '
110-
'it.';
111-
_logger.severe(message);
112108
done.complete(new BuildResult(BuildStatus.Failure, buildType, [],
113-
exception: message));
109+
exception: 'Build abandoned due to change to the build script or '
110+
'one of its dependencies. This could be caused by a pub get '
111+
'or any other change. Please terminate the build script and '
112+
'restart it.'));
114113
return;
115114
}
116115
}
@@ -139,16 +138,23 @@ class BuildImpl {
139138
new Asset(_assetGraphId, JSON.encode(_assetGraph.serialize()));
140139
await _writer.writeAsString(assetGraphAsset);
141140

142-
_logger.info('Build succeeded');
143141
done.complete(result);
144142
}, onError: (e, Chain chain) {
145-
_logger.severe('Build failed: $e\n\n${chain.terse}');
146143
done.complete(new BuildResult(BuildStatus.Failure, buildType, [],
147144
exception: e, stackTrace: chain.toTrace()));
148145
});
149146
var result = await done.future;
150147
_buildRunning = false;
151148
_isFirstBuild = false;
149+
if (result.status == BuildStatus.Success) {
150+
_logger.info('Succeeded after ${watch.elapsedMilliseconds}ms with '
151+
'${result.outputs.length} outputs\n');
152+
} else {
153+
var stackTraceString =
154+
result.stackTrace != null ? '\n\n${result.stackTrace}' : '';
155+
_logger.severe('Failed after ${watch.elapsedMilliseconds}ms:'
156+
'${result.exception}$stackTraceString\n');
157+
}
152158
return result;
153159
}
154160

@@ -344,13 +350,13 @@ class BuildImpl {
344350
// Check conflictingOuputs, prompt user to delete files.
345351
if (conflictingOutputs.isEmpty) return;
346352

347-
stdout.writeln('Found ${conflictingOutputs.length} declared outputs '
353+
stdout.writeln('\n\nFound ${conflictingOutputs.length} declared outputs '
348354
'which already exist on disk. This is likely because the `.build` '
349355
'folder was deleted, or you are submitting generated files to your '
350356
'source repository.');
351357
var done = false;
352358
while (!done) {
353-
stdout.write('Delete these files (y/n) (or list them (l))?: ');
359+
stdout.write('\nDelete these files (y/n) (or list them (l))?: ');
354360
var input = stdin.readLineSync();
355361
switch (input.toLowerCase()) {
356362
case 'y':

lib/src/generate/options.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ class BuildOptions {
5757
} else {
5858
color = _red;
5959
}
60-
var message = '$color[${record.level}]$_endColor ${record.loggerName}: '
60+
var message = '${Platform.isWindows ? '' : '\x1b[2K\r'}'
61+
'$color[${record.level}]$_endColor ${record.loggerName}: '
6162
'${record.message}${record.error != null ? "\n${record.error}" : ""}'
62-
'${record.stackTrace != null ? "\n${record.stackTrace}" : ""}\n';
63+
'${record.stackTrace != null ? "\n${record.stackTrace}" : ""}'
64+
'${record.level > Level.INFO || Platform.isWindows ? '\n' : ''}';
6365
if (record.level >= Level.SEVERE) {
6466
stderr.write(message);
6567
} else {

lib/src/generate/watch_impl.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class WatchImpl {
9292
await _resultStreamController.close();
9393
}
9494
_terminating = false;
95-
_logger.info('Build watching terminated, safe to exit.');
95+
_logger.info('Build watching terminated, safe to exit.\n');
9696
}
9797

9898
/// Runs a build any time relevant files change.

0 commit comments

Comments
 (0)