natefinch / lumberjack

lumberjack is a log rolling package for Go
MIT License
4.8k stars 591 forks source link

Callback on rotation #24

Open notzippy opened 8 years ago

notzippy commented 8 years ago

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..

natefinch commented 7 years ago

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.

lafriks commented 7 years ago

It could be used to send rotated logfiles to central server

glycerine commented 7 years ago

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.

yinonavraham commented 5 years ago

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).

darthShadow commented 1 year ago

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

coanor commented 1 year ago

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