Commit 18eac03d authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

VerboseLogger should just wrap the parent Logger (#10020)

This way, you can test things even with a VerboseLogger.
parent eaa93674
...@@ -180,12 +180,14 @@ class BufferLogger extends Logger { ...@@ -180,12 +180,14 @@ class BufferLogger extends Logger {
} }
class VerboseLogger extends Logger { class VerboseLogger extends Logger {
Stopwatch stopwatch = new Stopwatch(); VerboseLogger(this.parent) {
VerboseLogger() {
stopwatch.start(); stopwatch.start();
} }
final Logger parent;
Stopwatch stopwatch = new Stopwatch();
@override @override
bool get isVerbose => true; bool get isVerbose => true;
...@@ -221,7 +223,7 @@ class VerboseLogger extends Logger { ...@@ -221,7 +223,7 @@ class VerboseLogger extends Logger {
stopwatch.reset(); stopwatch.reset();
String prefix; String prefix;
const int prefixWidth = 8; const int prefixWidth = 12;
if (millis == 0) { if (millis == 0) {
prefix = ''.padLeft(prefixWidth); prefix = ''.padLeft(prefixWidth);
} else { } else {
...@@ -235,13 +237,13 @@ class VerboseLogger extends Logger { ...@@ -235,13 +237,13 @@ class VerboseLogger extends Logger {
final String indentMessage = message.replaceAll('\n', '\n$indent'); final String indentMessage = message.replaceAll('\n', '\n$indent');
if (type == _LogType.error) { if (type == _LogType.error) {
stderr.writeln(prefix + terminal.bolden(indentMessage)); parent.printError(prefix + terminal.bolden(indentMessage));
if (stackTrace != null) if (stackTrace != null)
stderr.writeln(indent + stackTrace.toString().replaceAll('\n', '\n$indent')); parent.printError(indent + stackTrace.toString().replaceAll('\n', '\n$indent'));
} else if (type == _LogType.status) { } else if (type == _LogType.status) {
print(prefix + terminal.bolden(indentMessage)); parent.printStatus(prefix + terminal.bolden(indentMessage));
} else { } else {
print(prefix + indentMessage); parent.printStatus(prefix + indentMessage);
} }
} }
} }
......
...@@ -161,7 +161,7 @@ class FlutterCommandRunner extends CommandRunner<Null> { ...@@ -161,7 +161,7 @@ class FlutterCommandRunner extends CommandRunner<Null> {
// Check for verbose. // Check for verbose.
if (globalResults['verbose']) { if (globalResults['verbose']) {
// Override the logger. // Override the logger.
context.setVariable(Logger, new VerboseLogger()); context.setVariable(Logger, new VerboseLogger(context[Logger]));
} }
String recordTo = globalResults['record-to']; String recordTo = globalResults['record-to'];
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_tools/src/base/logger.dart';
import 'package:test/test.dart';
void main() {
group('AppContext', () {
test('error', () async {
final BufferLogger mockLogger = new BufferLogger();
final VerboseLogger verboseLogger = new VerboseLogger(mockLogger);
verboseLogger.printStatus('Hey Hey Hey Hey');
verboseLogger.printTrace('Oooh, I do I do I do');
verboseLogger.printError('Helpless!');
expect(mockLogger.statusText, matches(r'^\[ (?: {0,2}\+[0-9]{1,3} ms| )\] Hey Hey Hey Hey\n'
r'\[ (?: {0,2}\+[0-9]{1,3} ms| )\] Oooh, I do I do I do\n$'));
expect(mockLogger.traceText, '');
expect(mockLogger.errorText, matches(r'^\[ (?: {0,2}\+[0-9]{1,3} ms| )\] Helpless!\n$'));
});
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment