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

Not deleting zipped log files #380

Open Livia-Peng opened 1 year ago

Livia-Peng commented 1 year ago

We're using the Winston daily logger like so:

{
  handleExceptions: true,
  formatter: formatter,
  filename: "/logs/ezlink-%DATE%.log",
  datePattern: "YYYY-MM-DD.HH.mm",
  zippedArchive: true,
  maxSize: "20m",
  maxFiles: 5
}

However, it's not deleting old zipped log files. I tested that not zipped files can be deleted. image

hyavari commented 8 months ago
this.logStream.on('logRemoved', function (params) {
    if (options.zippedArchive) {
        var gzName = params.name + '.gz';
        if (fs.existsSync(gzName)) {
            try {
                fs.unlinkSync(gzName);
            }
            catch (_err) {
                // file is there but we got an error when trying to delete,
                // so permissions problem or concurrency issue and another
                // process already deleted it we could detect the concurrency
                // issue by checking err.type === ENOENT or EACCESS for
                // permissions ... but then?
            }
            self.emit('logRemoved', gzName);
            return;
        }
    }
    self.emit('logRemoved', params.name);
});

It seems not easy to reproduce it. But for now, disabling the archiving is simpler.