diff --git a/lib/core/application.dart b/lib/core/application.dart new file mode 100644 index 0000000..a6d6aaf --- /dev/null +++ b/lib/core/application.dart @@ -0,0 +1,17 @@ +import 'dart:async'; + +import 'log.dart'; + +abstract class Application { + Application(Function() func) { + runZonedGuarded(() async { + func(); + }, (error, stack) { + writeInLog(error, stack); + }); + } + + void writeInLog(Object error, StackTrace stack) { + logError('$error:\n$stack'); + } +} diff --git a/lib/core/exception_manager.dart b/lib/core/exception_manager.dart new file mode 100644 index 0000000..808c1d0 --- /dev/null +++ b/lib/core/exception_manager.dart @@ -0,0 +1,8 @@ +class ExceptionnManager { + ExceptionnManager._privateConstructor(); + static final ExceptionnManager _instance = + ExceptionnManager._privateConstructor(); + static ExceptionnManager get to => _instance; + + void initialize() {} +} diff --git a/lib/core/log.dart b/lib/core/log.dart new file mode 100644 index 0000000..b3cf971 --- /dev/null +++ b/lib/core/log.dart @@ -0,0 +1,43 @@ +void log(String message) {} + +void logWarning(String message) { + _logSend(message, LogType.warning); +} + +void logError(String message) { + _logSend(message, LogType.error); +} + +void _logSend(String message, LogType type) { + var item = LogItem(message, type); + Log.to.append(item); +} + +enum LogType { verbose, error, warning } + +class LogItem { + late String message; + late String date; + late LogType type; + + LogItem(this.message, this.type) { + var now = DateTime.now(); + date = + '${now.year.toString().substring(2, 4)}-${now.month.toString().padLeft(2, '0')}-${now.day.toString().padLeft(2, '0')} ' + '${now.hour.toString().padLeft(2, '0')}:${now.minute.toString().padLeft(2, '0')}:${now.second.toString().padLeft(2, '0')}'; + } +} + +class Log { + Log._privateConstructor(); + static final Log _instance = Log._privateConstructor(); + static Log get to => _instance; + + final List logs = []; + + Log(); + + void append(LogItem item) { + logs.insert(0, item); + } +}