Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
leonzz opened this issue Sep 24, 2020 · 3 comments
Open

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

leonzz opened this issue Sep 24, 2020 · 3 comments

Comments

@leonzz
Copy link

leonzz commented Sep 24, 2020

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?

@natefinch natefinch reopened this Sep 24, 2020
@natefinch
Copy link
Owner

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
Copy link
Author

leonzz commented Sep 24, 2020

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
Copy link

rea1shane commented Mar 30, 2023

Hi @natefinch , I understand your perspective but also think rotate periodically is a good feature for many user, and i found a pr #103. If you need, i can make a pr based on https://github.com/robfig/cron. Can we complete it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants