Files
gps-speedo/lib/services/logger.dart
T
Mikkeli Matlock 2b2fc8fbd3 chore(01-01): create directory structure and infrastructure files
- Create lib/screens/, lib/widgets/, lib/providers/, lib/models/, lib/config/ directories
- Add Logger utility with error/warn/info/debug levels (kDebugMode guarded)
- Add GpsConfig constants (timeouts, heading validation)
- Add TimingConfig constants (heartbeat, overlay intervals)
- Add OverlayConfig constants (sizing, opacity ratios)
2026-02-09 21:22:19 +09:00

53 lines
2.0 KiB
Dart

import 'package:flutter/foundation.dart';
/// Logger utility for standardized debug output with color-coded severity levels.
/// All logging is guarded by kDebugMode and uses debugPrint to avoid truncation.
class Logger {
// ANSI color codes
static const String _red = '\x1B[31m';
static const String _yellow = '\x1B[33m';
static const String _blue = '\x1B[34m';
static const String _gray = '\x1B[90m';
static const String _reset = '\x1B[0m';
/// Log error-level message (red)
/// Used for failures, exceptions, critical issues
static void error(String message, [String? caller]) {
if (kDebugMode) {
final timestamp = DateTime.now().toUtc().toIso8601String();
final callerTag = caller != null ? ' [$caller]' : '';
debugPrint('$_red[ERROR] $timestamp$callerTag $message$_reset');
}
}
/// Log warning-level message (yellow)
/// Used for recoverable issues, unexpected states, deprecation warnings
static void warn(String message, [String? caller]) {
if (kDebugMode) {
final timestamp = DateTime.now().toUtc().toIso8601String();
final callerTag = caller != null ? ' [$caller]' : '';
debugPrint('$_yellow[WARN] $timestamp$callerTag $message$_reset');
}
}
/// Log info-level message (blue)
/// Used for lifecycle events, state transitions, user actions
static void info(String message, [String? caller]) {
if (kDebugMode) {
final timestamp = DateTime.now().toUtc().toIso8601String();
final callerTag = caller != null ? ' [$caller]' : '';
debugPrint('$_blue[INFO] $timestamp$callerTag $message$_reset');
}
}
/// Log debug-level message (gray)
/// Used for data flow, detailed state changes, verbose diagnostics
static void debug(String message, [String? caller]) {
if (kDebugMode) {
final timestamp = DateTime.now().toUtc().toIso8601String();
final callerTag = caller != null ? ' [$caller]' : '';
debugPrint('$_gray[DEBUG] $timestamp$callerTag $message$_reset');
}
}
}