Closed Harley-xk closed 3 months ago
You can use the "archiveLogFn" function to change the file name
log.transports.file.archiveLogFn = (oldLogFile) => {
const oldLogFilePath = oldLogFile.toString();
const info = path.parse(oldLogFilePath);
try {
const data = tools.buildDateTimeFileName();
fs.renameSync(oldLogFilePath, path.join(info.dir, `${info.name}.${data}${info.ext}`));
} catch (e) {
console.warn('Could not rotate log', e);
log.error('Could not rotate log', e);
}
}
The "tools.buildDateTimeFileName();" is a custom function to returns the current date in a format like "yyyyMMddHHmmss"
I hope this helps you
@Harley-xk Yes, I decided to use a simple log rotation with the possibility to customize it easily, as roicp mentioned.
When the log file reaches the maxSize limit (eg. 1M), the log file is renamed to a new file called
xxxx.old.log
. and when current log file reaches the maxSize again, the rotate fires. current log file renamed toxxx.old.log
again, whitch overrides the last generated 'old log' file.