log method

  1. @override
List<String> log(
  1. LogEvent event
)

Is called every time a new LogEvent is sent and handles printing or storing the message.

Implementation

@override
List<String> log(LogEvent event) {
  var color = PrettyPrinter.levelColors[event.level];
  var emoji = PrettyPrinter.levelEmojis[event.level];
  var methodName = _getMethodName();

  var methodNameSection =
  printCallingFunctionName && methodName != null ? ' | $methodName ' : '';
  var stackLog = event.stackTrace.toString();
  var output =
      '$emoji $className$methodNameSection - ${event.message}${printCallStack ? '\nSTACKTRACE:\n$stackLog' : ''}';

  if (exludeLogsFromClasses
      .any((excludeClass) => className == excludeClass) ||
      (showOnlyClass != null && className != showOnlyClass)) return [];

  final pattern = RegExp('.{1,800}'); // 800 is the size of each chunk
  List<String> result = [];

  for (var line in output.split('\n')) {
    result.addAll(pattern.allMatches(line).map((match) {
      if (kReleaseMode) {
        return match.group(0)!;
      } else {
        return color!(match.group(0)!);
      }
    }));
  }

  return result;
}