forked from
grain.social/native
this repo has no description
1import 'package:logger/logger.dart';
2
3class InMemoryLogOutput extends LogOutput {
4 static final List<String> _logs = [];
5
6 @override
7 void output(OutputEvent event) {
8 for (var line in event.lines) {
9 _logs.add(line);
10 }
11 }
12
13 static List<String> get logs => List.unmodifiable(_logs);
14 static void clear() => _logs.clear();
15}
16
17class SimpleLogPrinter extends LogPrinter {
18 final String className;
19
20 SimpleLogPrinter(this.className);
21
22 static const Map<Level, String> levelEmojis = {
23 Level.trace: '🔍',
24 Level.debug: '🐛',
25 Level.info: '💡',
26 Level.warning: '⚠️',
27 Level.error: '❌',
28 Level.fatal: '🔥',
29 };
30
31 @override
32 List<String> log(LogEvent event) {
33 final emoji = levelEmojis[event.level] ?? '';
34 final message = '$emoji $className - ${event.message}';
35 return [message]; // You can apply color here if needed
36 }
37}
38
39class DualLogOutput extends LogOutput {
40 final _inMemory = InMemoryLogOutput();
41 final _console = ConsoleOutput();
42
43 @override
44 void output(OutputEvent event) {
45 _inMemory.output(event);
46 _console.output(event);
47 }
48}
49
50// Globally available logger
51final appLogger = Logger(printer: SimpleLogPrinter('Grain'), output: DualLogOutput());