Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

538
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda