log method

String? log(
  1. Level logLevel,
  2. Object? message, {
  3. List<Object>? tags,
  4. LogFormat? customFormat,
})

Implementation

String? log(Level logLevel, Object? message,
    {List<Object>? tags, LogFormat? customFormat}) {
  if (_isLoggable(logLevel)) {
    if (message is Function) {
      message = message();
    }

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

    final LogRecord record = LogRecord(logLevel, msg, _stackFrame);
    final LogFormat usableFormat =
        customFormat ?? _globalFormat ?? _defaultFormat;

    if (_tagsFilter == null ||
        _tagsFilter?.isEmpty == true ||
        tags
                ?.map((Object e) => _tagsFilter?.contains(e))
                .where((bool? e) => e == true)
                .isNotEmpty ==
            true) {
      final String log = usableFormat(record);
      print(log);
      _afterLogging?.call(record);
      return log;
    }
  }
  return null;
}