winstonjs / winston-daily-rotate-file

A transport for winston which logs to a rotating file each day.
MIT License
895 stars 155 forks source link

Log not registering anymore if I even CAT the file... #303

Open quammy opened 3 years ago

quammy commented 3 years ago

Hi,

If I even look at the log file content using CAT, it stops registering any new entries. If I delete the file, it won't create a new one.

Is this normal? I come from .Net using Nlog and I didn't expect such a different behavior...

Maybe is my config? Here it is (short version):

const { createLogger, format, transports, config } = require('winston')
const helper = require('./helper')
require('winston-syslog')
require('winston-daily-rotate-file')

const fileTransport = new transports.DailyRotateFile({
    datePattern: 'YYYY-MM-DD',
    filename: 'aca-%DATE%.log',
    dirname: ".\\logs",
    maxSize: '20m',
    maxFiles: '14d'
    ,format: format.combine(format.colorize(), logFormat)
})

const logFormat = format.printf(logobj => {
    try {
        if (typeof logobj.message == 'string') { //} || logobj instanceof Object) {
            logobj.message = JSON.parse(logobj.message)
        }
    }
    catch (err) { }
    return `${logobj.level}: [${helper.getTimestamp()}] ${JSON.stringify(logobj.message, null, 4)}`
})

const logger = createLogger({
    exitOnError: false,
    format: format.simple(),
    levels: config.syslog.levels,
    transports: [
      //  papertrailTransport,
      //  consoleTransport,
        fileTransport
    ],
    colorize: true
});

Environment: Develop and test on Windows, Production run on Alpine within a Docker.

Thanks.