FlatStructuredPrinter constructor
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)
Implementation
FlatStructuredPrinter({
LogConfig? config,
List<String>? excludePaths
}) : config = config ?? LogConfig(), excludePaths = excludePaths ?? StackTraceParser.defaultExcludePaths;