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

File count rotate issue or requirement. #21

Closed
mattberther opened this issue Mar 10, 2016 · 5 comments
Closed

File count rotate issue or requirement. #21

mattberther opened this issue Mar 10, 2016 · 5 comments

Comments

@mattberther
Copy link
Member

Originally reported by @geforcesong at winstonjs/winston#660

Hello Guys,

I am using Winston for logging in my project. There is a requirement for us I don't know how to implement or can you please kindly modify the package to have that feature for us.
The thing is as follows,
when use file rotation and set maxfiles and maxsize, it works but it will add new file count at the end of each log file, which is

when set maxfiles to 5,
access.log, access1.log, access2.log, access3.log, access4.log
then it will keep increasing to,
access1.log, access2.log, access3.log, access4.log, access5.log
then it will keep increasing to,
access2.log, access3.log, access4.log, access5.log, access6.log

This is current behavior, however what we want is that if reach the maxfiles, we should use the first file name instead of increasing the file count all the time.
that is it will always have these files,
access.log, access1.log, access2.log, access3.log, access4.log

when reach the access4.log, then delete the first access.log and create a new access log and log the data in this file.
BTW, i have set the zippedArchive to true, but i didn't see the files got zipped

@kumar-b
Copy link

kumar-b commented Jun 16, 2016

Hi @mattberther,

I am trying to understand the requirement. When we reach the access4.log, then we delete the first access.log and create a new access log and log the data in this file. In this way it is difficult to know which is the latest log. Because it can be any one of them.
Log4j defines rotation policy in two ways. This way there is always a consistency that access.log will be the latest log.
https://logging.apache.org/log4j/2.x/manual/appenders.html#RolloverStrategies

Captured some snapshots from the above link.
1
2

@mattberther
Copy link
Member Author

@kumar-b would be interested in creating a rotate function (with tests) that satisfies the initial screenshot? Basically, the requirement is that access.log is always current and rotated files are in chronological order. Log4J refers to this as the "fixed window" strategy.

Once we have that, Id like to look for the best place to tie in the rotate function -- Ive done some investigation and found that rotation doesn't happen consistently either (especially when the file is buffered) and I think we'll need to do some refactoring to help with that. Isolating the rotate function in a separate class/module would help with this though.

Thoughts on the rotate api are:

function rotate(file, rotateOptions, cb) {
    this.count = rotateOptions.keep; // this comes from options.maxFiles in winston-daily-rotate-file
}

@nayimsust
Copy link

I am facing the same problem which @geforcesong mentioned. So is there any way to do that in Winton?

@marchaos
Copy link

+1 for this. It seems that the current behaviour is not what exists in most other logging frameworks. Normally I would expect the latest log file to be "access.log" rather than a log file with a number appended to it.

@mattberther
Copy link
Member Author

Resolving #23 will address this issue.

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

No branches or pull requests

4 participants