39 lines
953 B
Dart
39 lines
953 B
Dart
import 'package:flutter/foundation.dart';
|
|
|
|
abstract final class AppLogger {
|
|
static void debug(String tag, String message, [Object? error]) {
|
|
if (!kDebugMode) return;
|
|
_emit('D', tag, message, error);
|
|
}
|
|
|
|
static void info(String tag, String message) {
|
|
if (!kDebugMode) return;
|
|
_emit('I', tag, message);
|
|
}
|
|
|
|
static void warn(String tag, String message, [Object? error]) {
|
|
if (!kDebugMode) return;
|
|
_emit('W', tag, message, error);
|
|
}
|
|
|
|
|
|
static void error(
|
|
String tag,
|
|
String message,
|
|
Object error, [
|
|
StackTrace? stack,
|
|
]) {
|
|
_emit('E', tag, message, error);
|
|
if (stack != null && kDebugMode) {
|
|
debugPrint(
|
|
'[$tag] stack: ${stack.toString().split('\n').take(8).join('\n')}',
|
|
);
|
|
}
|
|
}
|
|
|
|
static void _emit(String level, String tag, String message, [Object? error]) {
|
|
final suffix = error != null ? ' err=$error' : '';
|
|
debugPrint('[$level/$tag] $message$suffix');
|
|
}
|
|
}
|