Google is committed to advancing racial equity for Black communities. See how.

log method

void log (Level logLevel, dynamic message, [Object error, StackTrace stackTrace, Zone zone])

Adds a log record 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. Level.INFO, Level.WARNING, etc) you can use their specialized methods instead (e.g. info, warning, etc).

If message is a Function, it will be lazy evaluated. Additionally, if message or its evaluated value is not a String, then 'toString()' will be called on the object and the result will be logged. The log record will contain a field holding the original object.

The log record will also contain a field for the zone in which this call was made. This can be advantageous if a log listener wants to handler records of different zones differently (e.g. group log records by HTTP request if each HTTP request handler runs in it's own zone).


void log(Level logLevel, message,
    [Object error, StackTrace stackTrace, Zone zone]) {
  Object object;
  if (isLoggable(logLevel)) {
    if (message is Function) {
      message = message();

    String msg;
    if (message is String) {
      msg = message;
    } else {
      msg = message.toString();
      object = message;

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

    var record =
        LogRecord(logLevel, msg, fullName, error, stackTrace, zone, object);

    if (parent == null) {
    } else if (!hierarchicalLoggingEnabled) {
    } else {
      var target = this;
      while (target != null) {
        target = target.parent;