How to daily rotate logs using Winston except the first day
For those who may still be looking for the right way, this ability was added in v.4.1.0.
Just use createSymlink
and symlinkName
options:
new DailyRotateFile({
...
createSymlink: true,
symlinkName: 'info.log',
});
Well one workaround can be to have one more transport to info.log
Just like this :
var logger = new (winston.Logger)({
transports: [
new dailyRotateFile(
{
//your definition of rotate file
}),
new (winston.transports.File)({ filename: 'info.log' })
]
});
And then set up some cron to delete info.log at midnight, i.e. node-schedule
However, with this approach there can be little inconsistency, if something is run through midnight, it can log few lines into info.log which belongs to next day and then it is deleted, therefore info.log can be incompleted.
But all the logs with this info.log.2016-08-09
format remains full and unaffected.
So it is to consider if very small chance to have incomplete info.log for one day is acceptable. (however you can create more advanced checker that does not just delete file, but looks if exist file of new day and if so, it looks whats inside and then delete only the logs from previous days from info.log and it does not delete it all at once)