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 prefix = _prefixes[record.level] ?? record.level.name;
return '$prefix:';
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) ? '\nStack: ${record.stackTrace}' : null;
case LogStep.THREAD:
return config.showThread ? '[main]' : null;
case LogStep.LOCATION:
if (!config.showLocation) return null;
final location = record.location;
return location != null ? '($location)' : null;
}
}