lumberjack
lumberjack copied to clipboard
Clean up based on total file size & avoid rotating empty file
Hi I'm building a periodic logic on top of lumberjack and there're 2 things that might be beneficial to others if implemented in lumberjack:
- when
Rotate()
is triggered from outside (in my case a periodic ticker), avoid rotating when the current log file is empty; - add an option to clean up based on total size across all back up files, because periodic rotation might create back up files less than the single file size limit, which makes it hard to control total size based on number of backups.
Does these features look useful and straightforward enough to add while maintaining simple API?
This is kind of why I don't advocate for periodic rotation. The whole point of rotation is to avoid running out of disk space. Plus it keeps the logic simple.
You could avoid rotating an empty log by checking the size yourself before calling rotate, but we can't change the behavior of rotate without potentially breaking people's code (if for some reason someone wanted to rotate an empty file).
The proposed 2 items won't make the logic more complex as they are pretty trivial to add to the current structure. The breaking part could be mitigated by a optional flag.
Adding these would make things easier for people who want to write periodic rotation on top, but much simpler than doing periodic rotation in this package-)
However I do understand your perspective. The use cases of periodic rotation is probably pretty different with what lumberjack was created for. My use case is to form a buffer backed by log files, so I need a way to periodically pop out all content from the buffer.
Hi @natefinch , I understand your perspective but also think rotate periodically is a good feature for many user, and i found a pr https://github.com/natefinch/lumberjack/pull/103. If you need, i can make a pr based on https://github.com/robfig/cron. Can we complete it?