I'm trying to use winston and winston-daily-rotate-file for log file rotation if the file size is greater than 5 MB.
I tried to delete the original log file via transport.on('rotate') event but It seems I do not have permission to delete the files or trying to empty the file content doesn't work either.
As per my understanding, winston should delete/empty the original log file after rotation occurs. Correct me if I am wrong
If notplease walk me to the best practie to achieve this.
My transport file goes like this:
const transport = new DailyRotateFile({
dirname: 'folderPath',
filename: 'abc', // no.log as I am mentioning it below
extension: '.log',
datePattern: 'YYYY-MM-DD-HH',
zippedArchive: true,
maxSize: 10000000, // 10 MB
maxFiles: '3',
prepend: true,
level: 'info',
});
Hello team,
I'm trying to use winston and winston-daily-rotate-file for log file rotation if the file size is greater than 5 MB.
I tried to delete the original log file via transport.on('rotate') event but It seems I do not have permission to delete the files or trying to empty the file content doesn't work either.
As per my understanding, winston should delete/empty the original log file after rotation occurs. Correct me if I am wrong If notplease walk me to the best practie to achieve this.
My transport file goes like this: const transport = new DailyRotateFile({ dirname: 'folderPath', filename: 'abc', // no.log as I am mentioning it below extension: '.log', datePattern: 'YYYY-MM-DD-HH', zippedArchive: true, maxSize: 10000000, // 10 MB maxFiles: '3', prepend: true, level: 'info', });
const logFormat = winston.format.combine( winston.format.colorize(), winston.format.align(), winston.format.printf( info =>
${moment().tz(moment.tz.guess()).format('MMM DD YYYY, hh:mm:ss A')}-${info.message}
, ),) const logger = winston.createLogger({ level: 'info', format: logFormat, transports: [ transport, new winston.transports.File({ filename: 'abc.log' }), ], });transport.on('rotate', function(oldFilename, newFilename) { fs.unlinkSync(folderPath + '/' + abc.log) fs.writeFile(folderPath + '/' + abc.log,'','UTF-8',function (err) { if (err) console.log('Error in writing to file-->'. err) })
Please let me know if any change required in this. Any help is much appreciated.