winstonjs / winston-daily-rotate-file

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

Filename not being followed - filename always has date appended #310

Open AriVagelatos-KSO opened 3 years ago

AriVagelatos-KSO commented 3 years ago

When I set the file name transport as follows (or without the datePattern option):

  transport = new (winston.transports.DailyRotateFile)({
    filename: "applicaton.log",
    datePattern: '',
    zippedArchive: true,
    maxSize: '20m',
    maxFiles: '14d'
  });

It appends the current date and creates a file with the name "application.log.2021-03-24". I need the name to be exactly as specified, without a date. The rolled file name isn't a concern. How can I achieve this?

Thank you

mattberther commented 3 years ago

You're looking for the symlink properties described at https://github.com/winstonjs/winston-daily-rotate-file#options. The below should meet your needs.

  transport = new (winston.transports.DailyRotateFile)({
    zippedArchive: true,
    maxSize: '20m',
    maxFiles: '14d',
    createSymlink: true,
    symlinkName: 'application.log',
  });
yuleicul commented 3 years ago

You're looking for the symlink properties described at https://github.com/winstonjs/winston-daily-rotate-file#options. The below should meet your needs.

  transport = new (winston.transports.DailyRotateFile)({
    zippedArchive: true,
    maxSize: '20m',
    maxFiles: '14d',
    createSymlink: true,
    symlinkName: 'application.log',
  });

This will cause an error:

internal/validators.js:124
    throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at validateString (internal/validators.js:124:11)
    at Object.dirname (path.js:1128:5)
    at new DailyRotateFile (/Users/yuleichen/Documents/gitlab/monitoring-platform-bff/node_modules/winston-daily-rotate-file/daily-rotate-file.js:72:48)
    at Object.<anonymous> (/Users/yuleichen/Documents/gitlab/monitoring-platform-bff/dist/logger/logger.config.js:26:9)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18) {
  code: 'ERR_INVALID_ARG_TYPE'
}

If I add dirname to the options, the error will disappear.

mattberther commented 3 years ago

You're right. https://github.com/winstonjs/winston-daily-rotate-file/blob/86a66af1b44cac15d7e779c28bcb893353556984/daily-rotate-file.js#L72 looks for options.filename rather than this.filename.

nikita-lipnyagov commented 3 years ago

@mattberther Does symlinkName option works correctly even if dirname option is added?

I use next options with winstonDailyRotateFile and as a result it creates winston.log.2021-05-07 file instead of info.log that I expect?

const createLogger: Function = 
    (filename: string): winston.Logger => winston.createLogger({
        level: 'info',
        format: formatter,
        transports: [new winstonDailyRotateFile({
            dirname: logsFolder,
            createSymlink: true,
            symlinkName: 'info.log',
            maxFiles: '7d'
        })]
    });
itsvamshiks commented 3 years ago

Hi is this issue solved? is there a configuration for winston to apply this behaviour ?

So like, Im trying to name the file as application.log instead of application.log.date

Darshilp326 commented 3 years ago

@mattberther Does symlinkName option works correctly even if dirname option is added?

I use next options with winstonDailyRotateFile and as a result it creates winston.log.2021-05-07 file instead of info.log that I expect?

const createLogger: Function = 
    (filename: string): winston.Logger => winston.createLogger({
        level: 'info',
        format: formatter,
        transports: [new winstonDailyRotateFile({
            dirname: logsFolder,
            createSymlink: true,
            symlinkName: 'info.log',
            maxFiles: '7d'
        })]
    });

Were you able to solve the issue? I am also stuck on this issue

mdottavi commented 3 years ago

@mattberther Does symlinkName option works correctly even if dirname option is added? I use next options with winstonDailyRotateFile and as a result it creates winston.log.2021-05-07 file instead of info.log that I expect?

const createLogger: Function = 
    (filename: string): winston.Logger => winston.createLogger({
        level: 'info',
        format: formatter,
        transports: [new winstonDailyRotateFile({
            dirname: logsFolder,
            createSymlink: true,
            symlinkName: 'info.log',
            maxFiles: '7d'
        })]
    });

Were you able to solve the issue? I am also stuck on this issue

I did the following, and it worked for me.

`

new transports.DailyRotateFile({
        level: 'warn',
        filename: './logs/error.%DATE%.log',
        auditFile: './logs/audits/error.audit.json',
        dirname: './logs',
        createSymlink: true,
        symlinkName: 'error.log',
        handleExceptions: true,
        json: false,
        maxSize: '20m',
        maxFiles: '7d',
        datePattern: 'YYYY-MM-DD',
        colorize: false,
        format: combine(
            format.colorize(),
            splat(),
            timestamp({ format: 'YYYY-MM-DD HH:mm:ss.SSS' }),
            myFormat
          ),    
    }),

` The result was in logs directory: error.2021-09-22.log error.log -> error.2021-09-22.log

tanu-17 commented 2 years ago

Any resolution for the same? It did not work for me. I need the filename without the date appended to it. For example error.log instead of error.2022-10-7.log.

wbt commented 2 years ago

@tanu-17 Did you try not having %DATE% in your filename?

DaCao commented 1 year ago

The last updated answer from @mdottavi worked very well for me

victorsun123 commented 3 months ago

@mattberther Is there a way, we can have the active log file named without date AND without usying symlink. We have a usecase where we pick up logs from a specific pattern, and unfortunately, the system is unable to pick up on symlinks due to security reasons.