log method
void
log(
- Level level,
- dynamic message, {
- DateTime? time,
- Object? error,
- StackTrace? stackTrace,
inherited
Log a message with level
.
Implementation
void log(
Level level,
dynamic message, {
DateTime? time,
Object? error,
StackTrace? stackTrace,
}) {
if (!_active) {
throw ArgumentError('Logger has already been closed.');
} else if (error != null && error is StackTrace) {
throw ArgumentError('Error parameter cannot take a StackTrace!');
} else if (level == Level.all) {
throw ArgumentError('Log events cannot have Level.all');
// ignore: deprecated_member_use_from_same_package
} else if (level == Level.off || level == Level.nothing) {
throw ArgumentError('Log events cannot have Level.off');
}
var logEvent = LogEvent(
level,
message,
time: time,
error: error,
stackTrace: stackTrace,
);
for (var callback in _logCallbacks) {
callback(logEvent);
}
if (_filter.shouldLog(logEvent)) {
var output = _printer.log(logEvent);
if (output.isNotEmpty) {
var outputEvent = OutputEvent(logEvent, output);
// Issues with log output should NOT influence
// the main software behavior.
try {
for (var callback in _outputCallbacks) {
callback(outputEvent);
}
_output.output(outputEvent);
} catch (e, s) {
print(e);
print(s);
}
}
}
}