Commit 15928fbd authored by Devon Carew's avatar Devon Carew Committed by GitHub

have app loggers log to their parent logger (#10402)

* have app loggers log to their parent logger

* rename field to parent

* add todo

* revert flutter_tools.iml change

* ping the bots
parent a8fe276c
...@@ -759,7 +759,7 @@ class AppInstance { ...@@ -759,7 +759,7 @@ class AppInstance {
} }
dynamic _runInZone(AppDomain domain, dynamic method()) { dynamic _runInZone(AppDomain domain, dynamic method()) {
_logger ??= new _AppRunLogger(domain, this, logToStdout: logToStdout); _logger ??= new _AppRunLogger(domain, this, parent: logToStdout ? logger : null);
final AppContext appContext = new AppContext(); final AppContext appContext = new AppContext();
appContext.setVariable(Logger, _logger); appContext.setVariable(Logger, _logger);
...@@ -768,20 +768,25 @@ class AppInstance { ...@@ -768,20 +768,25 @@ class AppInstance {
} }
/// A [Logger] which sends log messages to a listening daemon client. /// A [Logger] which sends log messages to a listening daemon client.
///
/// This class can either:
/// 1) Send stdout messages and progress events to the client IDE
/// 1) Log messages to stdout and send progress events to the client IDE
///
/// TODO(devoncarew): To simplify this code a bit, we could choose to specialize
/// this class into two, one for each of the above use cases.
class _AppRunLogger extends Logger { class _AppRunLogger extends Logger {
_AppRunLogger(this.domain, this.app, { this.logToStdout: false }); _AppRunLogger(this.domain, this.app, { this.parent });
AppDomain domain; AppDomain domain;
final AppInstance app; final AppInstance app;
final bool logToStdout; final Logger parent;
int _nextProgressId = 0; int _nextProgressId = 0;
@override @override
void printError(String message, { StackTrace stackTrace, bool emphasis: false }) { void printError(String message, { StackTrace stackTrace, bool emphasis: false }) {
if (logToStdout) { if (parent != null) {
stderr.writeln(message); parent.printError(message, stackTrace: stackTrace, emphasis: emphasis);
if (stackTrace != null)
stderr.writeln(stackTrace.toString().trimRight());
} else { } else {
if (stackTrace != null) { if (stackTrace != null) {
_sendLogEvent(<String, dynamic>{ _sendLogEvent(<String, dynamic>{
...@@ -800,18 +805,25 @@ class _AppRunLogger extends Logger { ...@@ -800,18 +805,25 @@ class _AppRunLogger extends Logger {
@override @override
void printStatus( void printStatus(
String message, String message, {
{ bool emphasis: false, bool newline: true, String ansiAlternative, int indent } bool emphasis: false, bool newline: true, String ansiAlternative, int indent
) { }) {
if (logToStdout) { if (parent != null) {
print(message); parent.printStatus(message, emphasis: emphasis, newline: newline,
ansiAlternative: ansiAlternative, indent: indent);
} else { } else {
_sendLogEvent(<String, dynamic>{ 'log': message }); _sendLogEvent(<String, dynamic>{ 'log': message });
} }
} }
@override @override
void printTrace(String message) { } void printTrace(String message) {
if (parent != null) {
parent.printTrace(message);
} else {
_sendLogEvent(<String, dynamic>{ 'log': message, 'trace': true });
}
}
Status _status; Status _status;
......
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