lumberjack icon indicating copy to clipboard operation
lumberjack copied to clipboard

Callback on rotation

Open notzippy opened this issue 8 years ago • 6 comments

Would be nice if lumberjack on rotation of the log file performed a callback so that additional action could be performed on the logs. This could be shoehorned in with the compression rotation #13 issue as well.

Details

  1. The interface would be RotateLogs(os.File) so exact location of the new file could be determined.
  2. The callback would be performed in a new thread so the logger will not need to be held up by any tasks that are being performed by the callback (for example compression).
  3. A public variable should be available within lumberjack so that a "default" compression utility could be used.

Just some thoughts..

notzippy avatar Jun 01 '16 21:06 notzippy

It's an interesting idea. I'm not really sure what other things people would want to do on rotation, though. I like that lumberjack has a very simple API right now, and I would like to try to keep it that way... but it's worth further thought.

natefinch avatar Nov 04 '16 13:11 natefinch

It could be used to send rotated logfiles to central server

lafriks avatar Nov 15 '16 21:11 lafriks

My use case for a callback is to preserve the program version information that I log on program startup. If this information gets rotated away, then it becomes tricky to track code version. Hence upon callback, I would write the version information again to the new log file.

glycerine avatar Apr 09 '17 14:04 glycerine

Another use case can be to move the backups to a different directory, other than the directory where the actual log file is located. The API can still be simple for the common use case, as today, but enable more advanced cases as mentioned in this thread. Any plans to progress with this? Is it OK to contribute a PR? (although it seems there is already a related open PR).

yinonavraham avatar Sep 15 '19 21:09 yinonavraham

I would like to use this to redirect stderr for panics etc. to the new log file. Something similar to what's already in this fork: https://github.com/svatantra/lumberjack

darthShadow avatar Dec 09 '22 06:12 darthShadow

My use case is to setup some Prometheuse metrics on log rotate, this may usefull to count how many files(bytes, approximately) been logged.

coanor avatar Jul 08 '23 09:07 coanor