Skip to content

Commit 0bb0c53

Browse files
committed
fix: Export only current session logs instead of all history
1 parent 0c1ceb1 commit 0bb0c53

File tree

1 file changed

+9
-24
lines changed

1 file changed

+9
-24
lines changed

electron/main.ts

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -591,34 +591,19 @@ ipcMain.handle('logs:get-path', () => {
591591

592592
ipcMain.handle('logs:export', async () => {
593593
try {
594-
if (!logFilePath || !fs.existsSync(logFilePath)) {
595-
return { success: false, error: 'No log file available' }
596-
}
597-
598-
// Flush the stream first
599-
if (logStream) {
600-
await new Promise<void>((resolve) => logStream!.write('', resolve))
601-
}
602-
603-
// Read all log files and combine them
604-
const logsDir = path.dirname(logFilePath)
605-
const logFiles = fs.readdirSync(logsDir)
606-
.filter(f => f.startsWith('bluepdm') && f.endsWith('.log'))
607-
.sort()
608-
.reverse() // Newest first
609-
610-
let combinedLogs = `BluePDM Logs Export\nExported: ${new Date().toISOString()}\nVersion: ${app.getVersion()}\nPlatform: ${process.platform} ${process.arch}\n${'='.repeat(60)}\n\n`
594+
// Export current session logs from memory buffer
595+
let sessionLogs = `BluePDM Session Logs\nExported: ${new Date().toISOString()}\nVersion: ${app.getVersion()}\nPlatform: ${process.platform} ${process.arch}\nEntries: ${logBuffer.length}\n${'='.repeat(60)}\n\n`
611596

612-
for (const file of logFiles) {
613-
const filePath = path.join(logsDir, file)
614-
const content = fs.readFileSync(filePath, 'utf-8')
615-
combinedLogs += `\n--- ${file} ---\n${content}\n`
597+
// Format each log entry
598+
for (const entry of logBuffer) {
599+
const dataStr = entry.data !== undefined ? ` ${JSON.stringify(entry.data)}` : ''
600+
sessionLogs += `[${entry.timestamp}] [${entry.level.toUpperCase()}] ${entry.message}${dataStr}\n`
616601
}
617602

618603
// Show save dialog
619604
const result = await dialog.showSaveDialog(mainWindow!, {
620-
title: 'Export Logs',
621-
defaultPath: `bluepdm-logs-${new Date().toISOString().replace(/[:.]/g, '-')}.txt`,
605+
title: 'Export Session Logs',
606+
defaultPath: `bluepdm-session-${new Date().toISOString().replace(/[:.]/g, '-')}.txt`,
622607
filters: [
623608
{ name: 'Text Files', extensions: ['txt'] },
624609
{ name: 'Log Files', extensions: ['log'] }
@@ -629,7 +614,7 @@ ipcMain.handle('logs:export', async () => {
629614
return { success: false, canceled: true }
630615
}
631616

632-
fs.writeFileSync(result.filePath, combinedLogs)
617+
fs.writeFileSync(result.filePath, sessionLogs)
633618
log('Logs exported to: ' + result.filePath)
634619

635620
return { success: true, path: result.filePath }

0 commit comments

Comments
 (0)