log method

  1. @override
List<String> log(
  1. LogRecord record
)
override

Formats the given LogRecord into a list of strings.

This method is called for each log event. The returned list of strings will be output line-by-line by the logging framework.

Each string in the list represents a line, allowing multi-line logs (such as those with stack traces or structured JSON).

Implementations should avoid side effects and keep formatting consistent.

Example return:

[
  "[INFO] Application started",
  "Details: version 1.0.0"
]

Implementation

@override
List<String> log(LogRecord record) {
  final color = levelColor(record.level);
  final buffer = <String>[];

  buffer.add(color('┌${'─' * (lineLength - 1)}'));

  for (final step in config.steps) {
    final content = getStepValue(step, record);
    if (content != null) {
      if (step == LogStep.STACKTRACE) {
        buffer.add(color('│ 📁 ${label("CALL STACK")}: '));
        final stackLines = extractStack(record.stackTrace, excludePaths);
        for (final line in stackLines) {
          buffer.add(color('│    • $line'));
        }
      } else {
        buffer.add(color('│ $content'));
      }
    }
  }

  buffer.add(color('└${'─' * (lineLength - 1)}'));
  return buffer;
}