mirror of
https://github.com/immich-app/immich.git
synced 2025-01-21 00:52:43 -05:00
chore(mobile): improve CSV log export (#1032)
This commit is contained in:
parent
d82dec9773
commit
765181bbc0
1 changed files with 24 additions and 16 deletions
|
@ -52,8 +52,7 @@ class ImmichLogger {
|
||||||
level: record.level.name,
|
level: record.level.name,
|
||||||
createdAt: record.time,
|
createdAt: record.time,
|
||||||
context1: record.loggerName,
|
context1: record.loggerName,
|
||||||
context2: record.stackTrace
|
context2: record.stackTrace?.toString(),
|
||||||
?.toString(), // Something more useful here? (e.g. stacktrace - I cannot get it to format nicely though)
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -62,26 +61,35 @@ class ImmichLogger {
|
||||||
_box.clear();
|
_box.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
shareLogs() async {
|
Future<void> shareLogs() async {
|
||||||
var tempDir = await getTemporaryDirectory();
|
final tempDir = await getTemporaryDirectory();
|
||||||
var filePath = '${tempDir.path}/${DateTime.now().toIso8601String()}.csv';
|
final dateTime = DateTime.now().toIso8601String();
|
||||||
var logFile = await File(filePath).create();
|
final filePath = '${tempDir.path}/Immich_log_$dateTime.csv';
|
||||||
// Write header
|
final logFile = await File(filePath).create();
|
||||||
logFile.writeAsStringSync("created_at,context_1,context_2,message,type\n");
|
final io = logFile.openWrite();
|
||||||
|
try {
|
||||||
|
// Write header
|
||||||
|
io.write("created_at,level,context,message,stacktrace\n");
|
||||||
|
|
||||||
// Write messages
|
// Write messages
|
||||||
for (var message in messages) {
|
for (final m in messages) {
|
||||||
logFile.writeAsStringSync(
|
io.write(
|
||||||
"${message.createdAt},${message.context1 ?? ""},${message.context2 ?? ""},${message.message},${message.level.toString()}\n",
|
'${m.createdAt},${m.level},"${m.context1 ?? ""}","${m.message}","${m.context2 ?? ""}"\n',
|
||||||
mode: FileMode.append,
|
);
|
||||||
);
|
}
|
||||||
|
} finally {
|
||||||
|
await io.flush();
|
||||||
|
await io.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Share file
|
// Share file
|
||||||
Share.shareFiles(
|
await Share.shareFiles(
|
||||||
[filePath],
|
[filePath],
|
||||||
subject: "Immich logs ${DateTime.now().toIso8601String()}",
|
subject: "Immich logs $dateTime",
|
||||||
sharePositionOrigin: Rect.zero,
|
sharePositionOrigin: Rect.zero,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Clean up temp file
|
||||||
|
await logFile.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue