From e3d216daa0a73559ed146723327d28978743ab0f Mon Sep 17 00:00:00 2001 From: Dennis Fokin Date: Wed, 18 Oct 2023 09:30:31 +0200 Subject: [PATCH] Add --log-file flag --- lib/desktop/init.dart | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/desktop/init.dart b/lib/desktop/init.dart index 5e4089bf..f8bb9710 100755 --- a/lib/desktop/init.dart +++ b/lib/desktop/init.dart @@ -243,7 +243,24 @@ Future _initHelper(String exe) async { } void _initLogging(List argv) { + final logFileIndex = argv.indexOf('--log-file'); + File? file; + if (logFileIndex != -1) { + final path = argv[logFileIndex + 1]; + file = File(path); + } Logger.root.onRecord.listen((record) { + if (logFileIndex != -1) { + if (file != null) { + file.writeAsStringSync( + '${record.time.logFormat} [${record.loggerName}] ${record.level}: ${record.message}${Platform.lineTerminator}', + mode: FileMode.append); + if (record.error != null) { + file.writeAsStringSync('${record.error}${Platform.lineTerminator}', + mode: FileMode.append); + } + } + } stderr.writeln( '${record.time.logFormat} [${record.loggerName}] ${record.level}: ${record.message}'); if (record.error != null) {