winstonjs / winston-daily-rotate-file

A transport for winston which logs to a rotating file each day.
MIT License
889 stars 151 forks source link

oldfilename of rotate event is not updated after renaming the file #350

Closed smnth90 closed 2 years ago

smnth90 commented 2 years ago

Hi,

Renamed and Moved the file to new folder. But we are getting the old oldFilename with the new event even after the file is renamed and moved to other folder.


    var installedDate=getTodayDate(); 
    let fileTransport = new (winston.transports.DailyRotateFile)({
          filename: getININLogPath(), //will give the path to save log files.
         datePattern: 'YYYY-MM-DD',
         zippedArchive: true,
         maxSize: '20k',// size=20kb
         maxFiles: '14d'
   });

   fileTransport.setMaxListeners(30);

   fileTransport.on('rotate', (oldFilename, newFilename) => {
          let currentDate=getTodayDate(); //getTodayDate will give the current date.
          if (currentDate!=installedDate) {
                   let newFile = `${currentDate}\file.log`; 
                   installedDate = currentDate; //compare the old date with new one and then rename old date folder to new one
                  fs.rename(newFilename, newFile, (err) => {
                           // eslint-disable-next-line no-console
                           if (err) { console.log('Failed to move the new file into todays folder', err); }
                           else { console.log('Successfully renamed file name to ', newFile); }
                 });
        }
   });

As maxSize is 20kb, new files will be created by appending incremented numbers to the log file. After date changes, we are renaming and moving the file to new date folder using the rename functionality. But from next event, we are getting oldFilename as older file name which consists of previous date folder path and some incremented number. It should be the new file name which is created or moved to new folder. We are using version number 3.10.0

I think this is a issue or if there is any way to update the oldFilename, please let us know

wbt commented 2 years ago

Duplicate of #349?

mattberther commented 2 years ago

Closing as a duplicate of #349