* opt: unused layout

* mod: semantics

* opt: DanmakuMsg type

* opt: avoid cast

* opt: unnecessary_lambdas

* opt: use isEven

* opt: logger

* opt: invalid common page

* tweak

* opt: unify DynController
This commit is contained in:
My-Responsitories
2025-08-27 12:01:53 +08:00
committed by GitHub
parent 56ffc2781f
commit 5f8313901b
83 changed files with 551 additions and 545 deletions

57
lib/services/logger.dart Normal file
View File

@@ -0,0 +1,57 @@
import 'dart:io';
import 'package:logger/logger.dart';
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';
final logger = PiliLogger();
class PiliLogger extends Logger {
PiliLogger() : super();
@override
Future<void> log(
Level level,
dynamic message, {
Object? error,
StackTrace? stackTrace,
DateTime? time,
}) async {
if (level == Level.error || level == Level.fatal) {
// 添加至文件末尾
File logFile = await LoggerUtils.getLogsPath();
logFile.writeAsString(
"**${DateTime.now()}** \n $message \n $stackTrace",
mode: FileMode.writeOnlyAppend,
);
}
super.log(level, "$message", error: error, stackTrace: stackTrace);
}
}
class LoggerUtils {
static File? _logFile;
static Future<File> getLogsPath() async {
if (_logFile != null) return _logFile!;
String dir = (await getApplicationDocumentsDirectory()).path;
final String filename = p.join(dir, ".pili_logs");
final File file = File(filename);
if (!file.existsSync()) {
await file.create(recursive: true);
}
return _logFile = file;
}
static Future<bool> clearLogs() async {
final file = await getLogsPath();
try {
await file.writeAsBytes(const [], flush: true);
} catch (e) {
// if (kDebugMode) debugPrint('Error clearing file: $e');
return false;
}
return true;
}
}