Skip to content

Commit

Permalink
Modify logNameGenerator to make log file names/coutput consistent and…
Browse files Browse the repository at this point in the history
… clearer
  • Loading branch information
Kiduzk committed Apr 22, 2024
1 parent 4c59514 commit 2e8216b
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions packages/main/src/services/logger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,27 @@ import * as rts from 'rotating-file-stream';
timber.hookConsole();

const logNameGenerator = (time, index) => {
const pad = num => (num > 9 ? '' : '0') + num;

if (!time) {
return path.join(app.getPath('userData'), 'logs', 'nuclear-error.log');
time = new Date();
index = 'current-log';
}

const month = time.getFullYear() + '' + pad(time.getMonth() + 1);
const day = pad(time.getDate());
const hour = pad(time.getHours());
const minute = pad(time.getMinutes());

const month = time.getFullYear().toString() + (time.getMonth() + 1).toString().padStart(2, '0');
const day = time.getDate().toString().padStart(2, '0');
const hour = time.getHours().toString().padStart(2, '0');
const minute = time.getMinutes().toString().padStart(2, '0');
return path.join(app.getPath('userData'), 'logs', `${month}/${month}${day}-${hour}${minute}-${index}-nuclear-error.log`);
};

const errorLogStream = rts.createStream(
logNameGenerator,
{
size: '1M',
maxFiles: 3,
compress: 'gzip'
size: '1M', // size and maxFiles are arbitrary value
maxFiles: 5,
compress: 'gzip',
history: path.join(app.getPath('userData'), 'logs', 'history-nuclear-error.log')
}
);

Expand Down

0 comments on commit 2e8216b

Please sign in to comment.