FmtPrinter class final

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"
Inheritance

Constructors

FmtPrinter({LogConfig? config})
A log printer that outputs logs in logfmt format.

Properties

config LogConfig
Configuration for customizing which log components are included.
final
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

extractStack(StackTrace? stackTrace, List<String> excludePaths) List<String>
Extracts the stack trace from a LogRecord.
inherited
getStepValue(LogStep step, LogRecord record) String?
Extracts the string representation of the given LogStep from a LogRecord.
override
levelColor(LogLevel level) AnsiColor
Returns the color for the given log level.
inherited
log(LogRecord record) List<String>
Formats the given LogRecord into a list of strings.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
stringify(dynamic message) String
Converts a message to its string representation.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited