Log 추가
This commit is contained in:
parent
635ac00aa2
commit
15f9a9aa70
3 changed files with 68 additions and 0 deletions
17
lib/core/application.dart
Normal file
17
lib/core/application.dart
Normal file
|
|
@ -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');
|
||||||
|
}
|
||||||
|
}
|
||||||
8
lib/core/exception_manager.dart
Normal file
8
lib/core/exception_manager.dart
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
class ExceptionnManager {
|
||||||
|
ExceptionnManager._privateConstructor();
|
||||||
|
static final ExceptionnManager _instance =
|
||||||
|
ExceptionnManager._privateConstructor();
|
||||||
|
static ExceptionnManager get to => _instance;
|
||||||
|
|
||||||
|
void initialize() {}
|
||||||
|
}
|
||||||
43
lib/core/log.dart
Normal file
43
lib/core/log.dart
Normal file
|
|
@ -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<LogItem> logs = [];
|
||||||
|
|
||||||
|
Log();
|
||||||
|
|
||||||
|
void append(LogItem item) {
|
||||||
|
logs.insert(0, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue