Close startup log connection and use portable export filenames

This commit is contained in:
Codex
2026-10-22 05:39:19 +03:00
parent 75517057d0
commit e04e70db2e
2 changed files with 8 additions and 3 deletions
@@ -24,7 +24,8 @@ abstract final class ImmichLogger {
try {
return await LogService.I.getMessages();
} on LoggerUnInitializedException {
final logs = DriftLogger.sqlite(await openSqliteConnection(name: 'immich_logs'));
final connection = await openSqliteConnection(name: 'immich_logs');
final logs = DriftLogger.sqlite(connection);
try {
return [
// if the log service had started, main would have logged this already
@@ -34,6 +35,7 @@ abstract final class ImmichLogger {
];
} finally {
await logs.close();
await connection.close();
}
}
}
@@ -41,7 +43,8 @@ abstract final class ImmichLogger {
static Future<void> shareLogs(BuildContext context, {String? startupError}) async {
final tempDir = await getTemporaryDirectory();
final dateTime = DateTime.now().toIso8601String();
final filePath = '${tempDir.path}/Immich_log_$dateTime.log';
final safeTimestamp = dateTime.replaceAll(':', '-');
final filePath = '${tempDir.path}/Immich_log_$safeTimestamp.log';
final logFile = await File(filePath).create();
final io = logFile.openWrite();
try {
@@ -28,7 +28,8 @@ void main() {
await tester.pumpWidget(const SizedBox());
await tester.runAsync(() async {
final logs = DriftLogger.sqlite(await openSqliteConnection(name: 'immich_logs'));
final connection = await openSqliteConnection(name: 'immich_logs');
final logs = DriftLogger.sqlite(connection);
await LogRepository(logs).insertAll([
LogMessage(
message: 'Failed to connect to old.example.net/203.0.113.9:443, uri=https://old.example.net/api',
@@ -37,6 +38,7 @@ void main() {
),
]);
await logs.close();
await connection.close();
await ImmichLogger.shareLogs(
tester.element(find.byType(SizedBox)),