diff --git a/app/logging.js b/app/logging.js index ba4f98231..7897b2879 100644 --- a/app/logging.js +++ b/app/logging.js @@ -104,21 +104,31 @@ async function deleteAllLogs(logPath) { }); } -function cleanupLogs(logPath) { +async function cleanupLogs(logPath) { const now = new Date(); const earliestDate = new Date( Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() - 3) ); - return eliminateOutOfDateFiles(logPath, earliestDate).then(remaining => { + try { + const remaining = await eliminateOutOfDateFiles(logPath, earliestDate); const files = _.filter(remaining, file => !file.start && file.end); if (!files.length) { - return null; + return; } - return eliminateOldEntries(files, earliestDate); - }); + await eliminateOldEntries(files, earliestDate); + } catch (error) { + console.error( + 'Error cleaning logs; deleting and starting over from scratch.', + error.stack + ); + + // delete and re-create the log directory + await deleteAllLogs(logPath); + mkdirp.sync(logPath); + } } function isLineAfterDate(line, date) { diff --git a/main.js b/main.js index 0e90caa42..512d04a71 100644 --- a/main.js +++ b/main.js @@ -632,17 +632,7 @@ app.on('ready', async () => { installPermissionsHandler({ session, userConfig }); - let loggingSetupError; - try { - await logging.initialize(); - } catch (error) { - loggingSetupError = error; - } - - if (loggingSetupError) { - console.error('Problem setting up logging', loggingSetupError.stack); - } - + await logging.initialize(); logger = logging.getLogger(); logger.info('app ready');