Initial commit
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user