@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.
Would accept patch request for this
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.
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)
@indexzero Is patch for this still acceptable ? I know this can by implemented via filename option but I can add another option for this.
it's not the task of individual daemons to each implement log rotation. this is why we have tools like logrotate, like @cemuzunlar said.
@cemuzunlar @Dieterbe
I agree, ideally, this wouldn't be winston's problem, but
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.
++1
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.
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.
Fixed by #205.
awesome!
Most helpful comment
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)