log static method

void log(
  1. String message, {
  2. D4LogLevel level = D4LogLevel.info,
  3. Object? error,
  4. StackTrace? stackTrace,
})

Implementation

static void log(String message,
    {D4LogLevel level = D4LogLevel.info, Object? error, StackTrace? stackTrace}) {
  if (!_shouldLog(level)) return;
  final now = DateTime.now();
  final timestamp = now
      .toIso8601String()
      .replaceFirst('T', ' ')
      .substring(0, 23); // yyyy-MM-dd HH:mm:ss.SSS
  final label = _levelLabels[level] ?? 'LOG';
  final color = _levelColors[level] ?? '';
  final output = StringBuffer();
  output.write('$color[$timestamp][$label] $message$_resetColor');
  if (error != null) {
    output.write(' | Error: $error');
  }
  if (stackTrace != null) {
    output.write('\n$stackTrace');
  }
  dPrint(output.toString());
}