If logs are malformed on startup, delete them all and start over
This commit is contained in:
parent
4b1ae1535d
commit
e4b0901620
2 changed files with 16 additions and 16 deletions
|
@ -104,21 +104,31 @@ async function deleteAllLogs(logPath) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function cleanupLogs(logPath) {
|
async function cleanupLogs(logPath) {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const earliestDate = new Date(
|
const earliestDate = new Date(
|
||||||
Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() - 3)
|
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);
|
const files = _.filter(remaining, file => !file.start && file.end);
|
||||||
|
|
||||||
if (!files.length) {
|
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) {
|
function isLineAfterDate(line, date) {
|
||||||
|
|
12
main.js
12
main.js
|
@ -632,17 +632,7 @@ app.on('ready', async () => {
|
||||||
|
|
||||||
installPermissionsHandler({ session, userConfig });
|
installPermissionsHandler({ session, userConfig });
|
||||||
|
|
||||||
let loggingSetupError;
|
await logging.initialize();
|
||||||
try {
|
|
||||||
await logging.initialize();
|
|
||||||
} catch (error) {
|
|
||||||
loggingSetupError = error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (loggingSetupError) {
|
|
||||||
console.error('Problem setting up logging', loggingSetupError.stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
logger = logging.getLogger();
|
logger = logging.getLogger();
|
||||||
logger.info('app ready');
|
logger.info('app ready');
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue