Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

542
Views
Winston-daily-rotate-file is not updating the oldfileName argument of rotate event listener after renaming the file

We are using winston-daily-rotate node.js module for logging. We are maintaining the logs date wise folder. So whenever the date changes, we are using rotate event listener and moving the file to new date folder by using the rename functionality. After renaming the file in rotate event call back function, the next rotate event is getting older filename but not the renamed filename.

Below is my code for winston rotate module producing logs on 24hr basis.

what changes i need to do in below code?

var installedDate=getTodayDate();// will give the date when service was started
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.
    let newFile = getININLogPath(); // will give the path to save log files.
    if (currentDate!=installedDate && process.env.ININ_TRACE_ROOT) {
        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); }
        });
    }
});

But this after renaming function (fs.rename(newFilename, newFile, (err)) its coming in previous date folder ex-if installed date is 2022-05-23 and next 2022-05-24 , logs of 24th also coming in 23th date.

Please let me know if any change required in this. Any help is much appreciated.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!