Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to rotate the file weekly & monthly? #112

Closed
ckmax opened this issue Nov 22, 2017 · 3 comments
Closed

Is it possible to rotate the file weekly & monthly? #112

ckmax opened this issue Nov 22, 2017 · 3 comments

Comments

@ckmax
Copy link

ckmax commented Nov 22, 2017

Hi,

I read through the documentation as well as the issues page and was unable to find a clear answer to this. How do you specify here the time interval in which the file rotates?

logger.add(logger.transports.DailyRotateFile, {
filename: '../NTI.log',
timestamp: true,
datePattern: 'yyyy-MM-dd.',
prepend: true,
maxSize: '10m',
level: process.env.ENV === 'development' ? 'debug' : 'info'
});

Also,

The new file that gets created since NTI.log is over 10m in size has a weird name : 'NTI.log.yyyy-11-We.' What am I doing wrong here?

Any input would help. Thanks a lot.

@mattberther
Copy link
Member

Some long-overdue refactoring of the transport has occurred. A PR is available at #107. Also, a pre-release version has been published to npm. Please npm install [email protected].

The option to set for monthly rotation is: datePattern: 'yyyy-MM'

Please respond back and let us know if the 2.0.0-beta isnt working for you.

@ckmax
Copy link
Author

ckmax commented Nov 29, 2017

i used the datePattern: 'YYYY-MM' and it is rotating every few hours. Can you explain this behavior?

Is there some documentation on the usage of the datePattern attribute?

EDIT:
Ok I see why this is happening, it was because I was restarting the app a few times for other things. Is there an option for it to not create new files after restarting? and just start logging from the latest rolled over file?

@mattberther
Copy link
Member

@ckmax First, please confirm that you're running the 2.0.0-beta version. The documentation for the datePattern property is here in the PR: 407f0cb#diff-04c6e90faac2675aa89e2176d2eec7d8R17

Also, I am unable to reproduce the issue you're describing. A small node script like the one below appends to the same file no matter how many times I run it.

var winston = require('winston');
require('winston-daily-rotate-file');
var randomString = require('./test/random-string');

var transport = new winston.transports.DailyRotateFile({
    filename: 'log',
    datePattern: 'YYYY-MM',
    level: 'info'
});

var logger = new (winston.Logger)({
    transports: [
        transport
    ]
});

logger.info(randomString(1056));
logger.info(randomString(1056));

If you continue to see this behavior, please respond with the minimal amount of code necessary to reproduce the issue.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants