getStepValue method

  1. @override
String? getStepValue(
  1. LogStep step,
  2. LogRecord record
)
override

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.TIMESTAMP:
      if (!config.showTimestamp) return null;
      final time = config.useHumanReadableTime
          ? LogCommons.formatTimestamp(record.time, true)
          : record.time.toIso8601String();
      return '⏰ TIME: $time';
    case LogStep.DATE:
      if (!config.showDateOnly || !config.showTimestamp) return null;
      return 'πŸ“… DATE: ${record.time.toIso8601String().split('T')[0]}';
    case LogStep.LEVEL:
      if (!config.showLevel) return null;
      final emoji = config.showEmoji ? LogCommons.levelEmojis[record.level] ?? '' : '';
      return '$emoji LEVEL: ${record.level.name}';
    case LogStep.TAG:
      return (config.showTag && record.loggerName != null && record.loggerName!.isNotEmpty)
          ? '🏷️ TAG: ${record.loggerName}'
          : null;
    case LogStep.MESSAGE:
      return 'πŸ’¬ MESSAGE: ${stringify(record.message)}';
    case LogStep.ERROR:
      return (record.error != null) ? '❌ ERROR: ${record.error}' : null;
    case LogStep.STACKTRACE:
      if (record.stackTrace == null) return null;
      final methodCountToUse = record.error != null ? errorMethodCount : methodCount;
      final formattedStack = StackTraceParser.formatStackTrace(
        record.stackTrace,
        methodCountToUse,
        excludePaths: excludePaths,
        stackTraceBeginIndex: stackTraceBeginIndex,
      );
      return formattedStack != null ? 'πŸ“‹ STACK:\n$formattedStack' : null;
    case LogStep.THREAD:
      return config.showThread ? '🧡 THREAD: main' : null;
    case LogStep.LOCATION:
      if (!config.showLocation) return null;
      final location = record.location;
      return location != null ? 'πŸ“ LOCATION: $location' : null;
  }
}