feat(logging): add global error handler
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'logger.dart';
|
||||
|
||||
class AppErrorHandler {
|
||||
final Logger _logger = getLogger('flutter.error');
|
||||
|
||||
void register() {
|
||||
FlutterError.onError = (details) {
|
||||
_logger.error(
|
||||
message: 'FlutterError: ${details.exceptionAsString()}',
|
||||
error: details.exceptionAsString(),
|
||||
stackTrace: details.stack ?? StackTrace.current,
|
||||
extra: {'context': 'FlutterError.onError'},
|
||||
);
|
||||
FlutterError.presentError(details);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,25 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'core/config/env.dart';
|
||||
import 'core/logging/logger.dart';
|
||||
import 'core/logging/log_service.dart';
|
||||
import 'core/logging/error_handler.dart';
|
||||
import 'app/di/injection.dart';
|
||||
import 'app/app.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
final logService = await LogService.create();
|
||||
Logger.setLogService(logService);
|
||||
|
||||
AppErrorHandler().register();
|
||||
|
||||
await configureDependencies();
|
||||
await Env.init();
|
||||
|
||||
getLogger(
|
||||
'app',
|
||||
).info(message: 'App starting...', extra: {'version': Env.version});
|
||||
|
||||
runApp(const LinksyApp());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user