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