fix(logging): fix static setLogService and null handling

This commit is contained in:
qzl
2026-04-01 14:36:09 +08:00
parent 49c062d5a5
commit d1092df254
2 changed files with 10 additions and 9 deletions
+1 -1
View File
@@ -51,7 +51,7 @@ class LogEntry {
final sb = StringBuffer();
sb.writeln('[$timestamp] ${level.name.toUpperCase()} [$module]');
if (funcName != null || lineNo != null) {
sb.write(' at $funcName' ?? '');
sb.write(' at ${funcName ?? ''}');
if (lineNo != null) sb.write(':$lineNo');
sb.writeln();
}
+9 -8
View File
@@ -2,14 +2,6 @@ import 'log_service.dart';
LogService? _globalLogService;
void setLogService(LogService service) {
_globalLogService = service;
}
LogService _ensureService() {
return _globalLogService ?? (throw StateError('LogService not initialized'));
}
class Logger {
final String module;
final LogService _service;
@@ -20,6 +12,15 @@ class Logger {
return Logger(module, _ensureService());
}
static void setLogService(LogService service) {
_globalLogService = service;
}
static LogService _ensureService() {
return _globalLogService ??
(throw StateError('LogService not initialized'));
}
void debug({
required String message,
Map<String, dynamic>? extra,