getStepValue method
Extracts the string representation of the given LogStep from a LogRecord.
Returns null if the step is disabled or the corresponding data is unavailable.
Implementation
@override
String? getStepValue(LogStep step, LogRecord record) {
switch (step) {
case LogStep.LEVEL:
if (!config.showLevel) return null;
final emoji = config.showEmoji ? LogCommons.levelEmojis[record.level] ?? '' : '';
return '$emoji[${record.level.name.substring(0, 1)}]';
case LogStep.MESSAGE:
return stringify(record.message);
case LogStep.TIMESTAMP:
if (!config.showTimestamp) return null;
if (config.showTimeOnly) {
final time = record.time.toLocal();
return '${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}:${time.second.toString().padLeft(2, '0')}';
}
return config.useHumanReadableTime
? LogCommons.formatTimestamp(record.time, true)
: record.time.toIso8601String();
case LogStep.DATE:
if (!config.showDateOnly || !config.showTimestamp) return null;
return record.time.toIso8601String().split('T')[0];
case LogStep.TAG:
return (config.showTag && record.loggerName != null && record.loggerName!.isNotEmpty) ? '[${record.loggerName}]' : null;
case LogStep.ERROR:
return (record.error != null) ? 'ERROR: ${record.error}' : null;
case LogStep.STACKTRACE:
return (record.stackTrace != null) ? '\n${record.stackTrace}' : null;
case LogStep.THREAD:
return config.showThread ? '[T:main]' : null;
case LogStep.LOCATION:
if (!config.showLocation) return null;
final location = record.location;
return location != null ? '($location)' : null;
}
}