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

How can I determine when the file stream has finished writing? #373

Open Hawley-hy opened 1 year ago

Hawley-hy commented 1 year ago
const winston = require('winston');
const DailyRotateFile = require('winston-daily-rotate-file');

const logger = winston.createLogger({
  transports: [
    new DailyRotateFile({
      dirname: 'logs',
      filename: 'log-%DATE%.log',
      datePattern: 'YYYY-MM-DD',
      zippedArchive: true,
    }),
  ],
});

logger.info('This is a log message.');

const currentDate = new Date().toISOString().slice(0, 10);

const logFileName = `log-${currentDate}.log`;

const logFileStream = logger.transports[0].stream;
logFileStream.on('finish', () => {
  console.log(`${logFileName}  stream done!`); // Not working ....
});

logFileStream.end();
Hawley-hy commented 1 year ago

please someone could help me.