FlatStructuredPrinter class final

A structured log printer that formats log records with optional indentation and stack traces.

This printer outputs each log record as a structured single-line summary followed by additional indented lines for the stack trace if it is present and enabled in the config. It offers better readability compared to flat output, especially when errors and stack traces are involved.

The log content is customized through the LogConfig object, which determines which LogSteps to include (timestamp, level, message, etc.).

Example

final printer = FlatStructuredPrinter();
final record = LogRecord(
  level: LogLevel.error,
  message: 'Something went wrong!',
  time: DateTime.now(),
  stackTrace: StackTrace.current,
);

final output = printer.log(record);
for (final line in output) {
  print(line);
}

// Output example:
// [ERROR][Something went wrong!]
//   ↪ #0 MyApp._handleError (main.dart:42)
//   ↪ #1 runApp (main.dart:50)
//   ↪ #2 main (main.dart:10)
Inheritance

Constructors

FlatStructuredPrinter({LogConfig? config, List<String>? excludePaths})
A structured log printer that formats log records with optional indentation and stack traces.

Properties

config LogConfig
Configuration for customizing the log output format.
final
excludePaths List<String>
List of paths to exclude from stack traces
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