log method

void log(
  1. LoggingLevel level,
  2. Object data, {
  3. String? logger,
  4. Meta? meta,
})

Sends a LoggingMessageNotification to the client, if the loggingLevel is <= level.

The data must either be some json serializable object, or a function which takes no arguments and returns some json serializable object.

if data is a function then it must take zero arguments and return a non-nullable result. It will only be invoked if the log message will actually be sent.

If data is any other type of function, an ArgumentError will be thrown.

Implementation

void log(LoggingLevel level, Object data, {String? logger, Meta? meta}) {
  if (loggingLevel > level) return;

  if (data is Function) {
    if (data is Object Function()) {
      data = data();
    } else {
      throw ArgumentError.value(
        data,
        'data',
        'When logging a lazily evaluated function, it must be of type '
            '`Object Function()`, but the given function type was '
            '`${data.runtimeType}`.',
      );
    }
  }

  sendNotification(
    LoggingMessageNotification.methodName,
    LoggingMessageNotification(
      level: level,
      data: data,
      logger: logger,
      meta: meta,
    ),
  );
}