FmtPrinter constructor

FmtPrinter({
  1. LogConfig? config,
})

A log printer that outputs logs in logfmt format.

This printer converts log records into a series of key-value pairs suitable for machine parsing and log aggregation systems like Loki, Datadog, or Fluentd.

Keys such as level, msg, time, and others are included based on the steps defined in the LogConfig. Strings are properly escaped and quoted to comply with the logfmt specification.

Example

final printer = FmtPrinter();
final record = LogRecord(
  level: LogLevel.warning,
  message: 'Disk space low',
  time: DateTime.now(),
  loggerName: 'SystemMonitor',
);

final output = printer.log(record);
print(output.first);

// Example output:
// level=warning msg="Disk space low" time="2025-06-23T15:00:00.000Z" logger="SystemMonitor"

Implementation

FmtPrinter({LogConfig? config}) : config = config ?? LogConfig();