PrefixPrinter class final

A customizable log printer that prepends a prefix to each log line.

This printer is ideal when you want to prepend symbols, emojis, or abbreviations that help visually distinguish log levels. For example, you can use emojis like:

  • πŸ” DEBUG
  • ⚠️ WARNING
  • ❌ ERROR

If LogConfig.showEmoji is enabled and no custom prefix map is provided, default emojis from LogCommons.levelEmojis will be used.

It supports formatting options like timestamps, tags, errors, and stack traces based on the provided LogConfig.

Example

final printer = PrefixPrinter(
  config: LogConfig(showLevel: true, showTimestamp: true, showEmoji: true),
);

final record = LogRecord(
  level: LogLevel.info,
  message: 'User login succeeded',
  time: DateTime.now(),
  loggerName: 'AuthService',
);

final lines = printer.log(record);
lines.forEach(print);

// Output:
// πŸ”·: [12:30:00] [AuthService] User login succeeded
Inheritance

Constructors

PrefixPrinter({Map<LogLevel, String>? prefixes, LogConfig? config})
A customizable log printer that prepends a prefix to each log line.

Properties

config β†’ LogConfig
Configuration object that controls what 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