Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfixes #273

Merged
merged 5 commits into from
Oct 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: Do not try to create a random log file
bdlukaa committed Oct 1, 2024

Verified

This commit was signed with the committer’s verified signature.
AetherUnbound Madison Swain-Bowden
commit 836831a3d7fbac50a4b1a4569f1878c17d2da9ef
15 changes: 7 additions & 8 deletions lib/utils/logging.dart
Original file line number Diff line number Diff line change
@@ -45,12 +45,12 @@ void handleError(
writeErrorToFile(error, stackTrace, context);
}

Future<File> getLogFile() async {
Future<File?> getLogFile() async {
try {
return File(path.join(supportDir.path, 'logs.txt'));
} catch (e) {
debugPrint('Error getting log file: $e');
return File('./logs.txt');
// debugPrint('Error getting log file: $e');
return null;
}
}

@@ -67,9 +67,8 @@ Future<void> writeErrorToFile(
'[$time]Stack trace: $stackTrace';

final file = await getLogFile();

await file.writeAsString(errorLog, mode: FileMode.append);
Logger.root.log(Level.INFO, 'Wrote log file to "${file.path}"');
await file?.writeAsString(errorLog, mode: FileMode.append);
Logger.root.log(Level.INFO, 'Wrote log file to "${file?.path}"');
Logger.root.log(Level.SEVERE, errorLog);
}

@@ -78,8 +77,8 @@ Future<void> writeLogToFile(String text, {bool print = false}) async {
final time = DateTime.now().toIso8601String();
final file = await getLogFile();

await file.writeAsString('\n[$time] $text', mode: FileMode.append);
if (print) Logger.root.log(Level.INFO, 'Wrote log file to "${file.path}"');
await file?.writeAsString('\n[$time] $text', mode: FileMode.append);
if (print) Logger.root.log(Level.INFO, 'Wrote log file to "${file?.path}"');
}
if (print) debugPrint(text);
}