log static method

void log(
  1. String level,
  2. dynamic message, [
  3. dynamic data,
  4. String? tag,
])

tag names where the line comes from, like request or server. No tag gives app. It is the third positional argument, because Dart does not allow a named argument next to the optional data.

Logger.info('done', null, 'billing');

Implementation

static void log(String level, dynamic message, [dynamic data, String? tag]) {
  // an empty tag would print `[]`
  if (tag == null || tag.isEmpty) tag = 'app';
  // `INFO` from a filter ranks as `info`
  level = level.toLowerCase();
  LoggerConfig config = Dox().config.logger;
  if (!config.enabled || !shouldLog(level, config.level)) return;
  String line;
  try {
    line = _build(config, level, message, data, tag);
  } catch (_) {
    // data that can not become JSON must not break the caller (eg. a
    // request). Log its text instead.
    try {
      line = _build(config, level, message, data?.toString(), tag);
    } catch (_) {
      return;
    }
  }
  // a warning or an error is written at once, it must not be lost
  LogBuffer.write(line, now: (_ranks[level] ?? 3) >= 2);
}