-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: error logging for desktop and android (#180)
* feat: error loging for desktop and android * change route from home to setting-bugreport * delete conflict files * feat: extension search and separation by types (#192) * feat: extension search and separation by types * Refactor extensionCards filtering logic * perf: extension load optimisation (#193) * Add logging and share_plus dependencies --------- Co-authored-by: MiaoMint <44718819+MiaoMint@users.noreply.github.com> Co-authored-by: MiaoMint <miaomint@0u0.ren>
- Loading branch information
1 parent
d391ae8
commit bc03074
Showing
13 changed files
with
190 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/foundation.dart'; | ||
import 'package:logging/logging.dart'; | ||
import 'package:miru_app/utils/miru_directory.dart'; | ||
import 'package:miru_app/utils/miru_storage.dart'; | ||
import 'package:path/path.dart' as path; | ||
|
||
final logger = Logger('Miru'); | ||
|
||
class MiruLog { | ||
static final logFilePath = path.join(MiruDirectory.getDirectory, 'miru.log'); | ||
|
||
static void ensureInitialized() { | ||
Logger.root.level = Level.ALL; | ||
Logger.root.onRecord.listen((record) { | ||
final log = | ||
'${record.loggerName} ${record.level.name} ${record.time}: ${record.message} ${record.error ?? ''} ${record.stackTrace ?? ''}'; | ||
// 如果是开发环境则打印到控制台 | ||
if (kReleaseMode) { | ||
writeLogToFile(log); | ||
return; | ||
} | ||
|
||
debugPrint(log); | ||
}); | ||
} | ||
|
||
// 写入日志到文件 | ||
static void writeLogToFile(String log) { | ||
if (!MiruStorage.getSetting(SettingKey.saveLog)) { | ||
return; | ||
} | ||
final file = File(logFilePath); | ||
file.writeAsStringSync('$log\n', mode: FileMode.append); | ||
if (file.lengthSync() > 1024 * 1024 * 10) { | ||
file.deleteSync(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.