Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

537
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda