log method

void log(
  1. LogLevel logLevel,
  2. dynamic message, [
  3. Object? error,
  4. StackTrace? stackTrace,
])

Adds a log entry for a message at a particular logLevel if isLoggable(logLevel) is true.

Use this method to create log entries for user-defined levels. To record a message at a predefined level (e.g. LogLevel.INFO, LogLevel.WARNING, etc) you can use their specialized methods instead (e.g. info, warning, etc).

toString() will be called on the message object.

Implementation

void log(LogLevel logLevel, message,
    [Object? error, StackTrace? stackTrace]) {
  if (isLoggable(logLevel)) {
    final msg = message.toString();

    if (stackTrace == null && logLevel >= recordStackTraceAtLevel) {
      stackTrace = StackTrace.current;
      error ??= 'autogenerated stack trace for $logLevel $msg';
    }

    if (error != null || stackTrace != null) {
      logEntryStreamController.add(LogEntry.withError(
          logLevel, msg, name, error?.toString(), stackTrace?.toString()));
    } else {
      logEntryStreamController.add(LogEntry.standard(logLevel, msg, name));
    }
  }
}