PrefixPrinter constructor
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
Implementation
PrefixPrinter({
Map<LogLevel, String>? prefixes,
LogConfig? config,
}) : _prefixes = prefixes ?? (config?.showEmoji == true ? LogCommons.levelEmojis : {}),
config = config ?? LogConfig();