log method

void log(
  1. Level level,
  2. dynamic message, [
  3. dynamic error,
  4. StackTrace? stackTrace,
])
inherited

Log a message with level.

Implementation

void log(Level level, dynamic message,
    [dynamic 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.nothing) {
    throw ArgumentError('Log events cannot have Level.nothing');
  }
  var logEvent = LogEvent(level, message, error, stackTrace);
  if (_filter.shouldLog(logEvent)) {
    for (var callback in _logCallbacks) {
      callback(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);
      }
    }
  }
}