mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
fix: 日期转换失败导致日志无法显示,新增fatal等级记录,统一日志文件获取
This commit is contained in:
@@ -18,12 +18,10 @@ class PiliLogger extends Logger {
|
||||
@override
|
||||
void log(Level level, dynamic message,
|
||||
{Object? error, StackTrace? stackTrace, DateTime? time}) async {
|
||||
if (level == Level.error) {
|
||||
String dir = (await getApplicationDocumentsDirectory()).path;
|
||||
// 创建logo文件
|
||||
final String filename = p.join(dir, ".pili_logs");
|
||||
if (level == Level.error || level == Level.fatal) {
|
||||
// 添加至文件末尾
|
||||
await File(filename).writeAsString(
|
||||
File logFile = await getLogsPath();
|
||||
logFile.writeAsString(
|
||||
"**${DateTime.now()}** \n $message \n $stackTrace",
|
||||
mode: FileMode.writeOnlyAppend,
|
||||
);
|
||||
@@ -35,17 +33,15 @@ class PiliLogger extends Logger {
|
||||
Future<File> getLogsPath() async {
|
||||
String dir = (await getApplicationDocumentsDirectory()).path;
|
||||
final String filename = p.join(dir, ".pili_logs");
|
||||
final file = File(filename);
|
||||
final File file = File(filename);
|
||||
if (!await file.exists()) {
|
||||
await file.create();
|
||||
await file.create(recursive: true);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
Future<bool> clearLogs() async {
|
||||
String dir = (await getApplicationDocumentsDirectory()).path;
|
||||
final String filename = p.join(dir, ".pili_logs");
|
||||
final file = File(filename);
|
||||
final File file = await getLogsPath();
|
||||
try {
|
||||
await file.writeAsString('');
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user