How to get Winston daily file rotate to log to corresponding level file

Viewed 1378

I have defined custom levels for my application .They are as follows.

protected levels: Level = {
        "error": 0,
        "warn": 1,
        "info": 2,
        "debug": 3,
        "trace": 4
    };

I am using daily file rotate transport to get daily log in separate files.

    const options: Object = {
        name: this.level,
        filename: logFilePath,
        dirname: WinstonLogAgent.DIR_LOG,
        datePattern: "yyyyMMdd.",
        prepend: true,
        level: this.level,
        levels: this.levels,
        maxsize: this.maxFileSize,
        maxFiles: this.maxFileCount,
        handleExceptions: true,
        humanReadableUnhandledException: true
    };

    this.transportInstance.push(new (winston.transports.DailyRotateFile)(options));

If i define log level to be 'info', it will create one log file named info.log and will log for levels 'info' , 'warn' and 'error' (trace and debug will be ignored).

But behaviour i wanted was different. If i am specifying level to be 'info' and i am logging levels 'info' , 'warn' and 'error' , then there should be separate files created for each type of log . i.e 'info' level should be logged to info.log and 'warn' level to be logged to warn.log.

I have tried specifying five different daily file rotate transport ,each with unique level. Then the problem i find is that there is duplicate log entries. For example , if am logging 'error' level , it would log to info.log , warn.log & error.log when logging level is set to info.

How can i achieve my objective?

1 Answers
Related