Skip to content

Commit

Permalink
If logs are malformed on startup, delete them all and start over
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Mar 13, 2019
1 parent 4b1ae15 commit e4b0901
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
20 changes: 15 additions & 5 deletions app/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 1 addition & 11 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down

0 comments on commit e4b0901

Please sign in to comment.