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

Add ability for File transport to split up logs by date #10

Closed
Marak opened this issue May 29, 2011 · 13 comments
Closed

Add ability for File transport to split up logs by date #10

Marak opened this issue May 29, 2011 · 13 comments
Labels
Feature Request Request for new functionality to support use cases not already covered

Comments

@Marak
Copy link
Contributor

Marak commented May 29, 2011

@indexzero -

How would you feel about adding an optional API parameter to the File transport so that it can split up log files by date? The idea would be that on each new day, a new log file would be created and Winston would automatically handle all of this / know which log file to write to based on the date.

@indexzero
Copy link
Member

Would accept patch request for this

@Marak
Copy link
Contributor Author

Marak commented May 29, 2011

Cool! Any suggestions for an API? I was thinking something like:

           // Specify path option and default to spanning by day ( 24 hours in each file )
           new (winston.transports.File)({ path: './logs' })

but there might be some utility in allowing for a custom date / time filter.

@cemuzunlar
Copy link

There is no need to complicate the winston code when there is a standard tool for this task: Logrotate (http://linuxcommand.org/man_pages/logrotate8.html)

@pkrefta
Copy link

pkrefta commented Jul 10, 2012

@indexzero Is patch for this still acceptable ? I know this can by implemented via filename option but I can add another option for this.

@Dieterbe
Copy link

it's not the task of individual daemons to each implement log rotation. this is why we have tools like logrotate, like @cemuzunlar said.

@EugenDueck
Copy link

@cemuzunlar @Dieterbe

I agree, ideally, this wouldn't be winston's problem, but

  • winston does run on Windows, which does not have logrotate, despite several (feeble looking) simple attempts on various blogs (and some suggestions to use cygwin + a self-compiled logrotate, but I doubt that would even be possible on theoretical grounds, assuming that winston keeps the file open for writing, which severely restricts what you can do with that file on Windows)
  • winston's file transport already does log rotation, only it splits by file size, not date. And it also deletes old files, so it's all of basic log rotation functionality

@Dieterbe
Copy link

I see...
thinking out loud: moving log rotation logic into a separate node program, so it's a reusable simple logrotate clone that works across platforms.

@SoulRaven
Copy link

++1

@pccowboy
Copy link

While I am also an advocate of logrotate, it does not do its work alone. Logrotate is so very usable because it provides a method to tell programs that it is time to flush and close their logs.

The file transport has a _createStream.checkFile.createAndFlush function that at first glance looks like it should do the appropriate things. To use this for logrotate, have your node program trap SIGHUP and access this function. I don't have time before my dayjob to post code, but I will try tonight and post my results.

Responding to SIGHUP in this fashion should be transportable to windows, and then whatever log rotation you use on windows (node library or other magic) is left as an exercise to the reader.

@suprememoocow
Copy link

In case anyone else is looking for this:

Thanks for the tip, @pccowboy. I'm a big advocate of logrotate too. I'm reluctant to use one configuration for node.js service (ie winston File maxsize, etc) and another (logrotate) for other services (nginx, redis, etc) and would prefer to use logrotate for all my logfiles. I've put together a simple function which will listen to HUP signals and reopen the log file postrotate.

If I get a chance, I'll try rewrite this in a cleaner manner (ie, as a configuration option for the File transport) and create a pull request.

https://gist.github.com/suprememoocow/5133080

@indexzero
Copy link
Member

Fixed by #205.

@jcldavid
Copy link

awesome!

@sanketJariwala9464
Copy link

How to create weekly log using Winston daily rotate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Request for new functionality to support use cases not already covered
Projects
None yet
Development

No branches or pull requests