translate method
Implementation
@override
void translate(LogEntry entry, LogTranslatorNextFunction? next) {
final now = DateTime.now();
final logLevelPainter = _levelColor[entry.level] ?? dummyStringMapper;
final levelLabel = _levelLabel[entry.level] ?? 'DBG';
final logLevel = _lgp('[') + logLevelPainter(levelLabel) + _lgp(']');
var category = entry.category;
if (diffTime) {
final lastTime = _categoryLastTime[entry.category] ?? now;
final duration = prettyDuration(
now.difference(lastTime),
abbreviated: true,
tersity: DurationTersity.millisecond,
);
category += ' +$duration';
_categoryLastTime[entry.category] = now;
}
if (alignMessages) {
_categoryMaxLength = max(_categoryMaxLength, category.length);
category = category.padRight(_categoryMaxLength);
}
if (textPainter is NoColorsTextPainter) {
category += ' -';
}
category = _gp(category);
var dateTime = _timestampFormatter.format(now);
if (timestampFormat.contains('.S')) {
// dim microseconds
dateTime = dateTime.replaceAllMapped(RegExp(r'\.\d{3}'), (match) {
return _lgp(match.group(0)!);
});
}
// prepare context
for (var i = 0; i < entry.context.length; i++) {
entry.context[i] = entry.context[i].toString();
}
// delimiter between message and context if they are on the same line
if (entry.context.isNotEmpty) {
final firstElement = entry.context.first;
if (firstElement is String && !firstElement.startsWith('\n')) {
entry.context.insert(0, _lgp(':'));
}
}
final lineItems = [
dateTime,
logLevel,
category,
entry.message,
...entry.context.map((e) => e.toString()),
];
final lineStr = lineItems.where((s) => s != '').join(' ');
_printer(lineStr.trim());
if (next != null) next(entry);
}