natefinch / lumberjack

lumberjack is a log rolling package for Go
MIT License
4.76k stars 585 forks source link

Clean up based on total file size & avoid rotating empty file #111

Open leonzz opened 3 years ago

leonzz commented 3 years ago

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:

Does these features look useful and straightforward enough to add while maintaining simple API?

natefinch commented 3 years ago

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

leonzz commented 3 years ago

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.

rea1shane commented 1 year ago

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?