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

added RollingInterval, to rotate file every x sec. #101

Open
wants to merge 3 commits into
base: v2.0
Choose a base branch
from

Conversation

oryaacov
Copy link

@oryaacov oryaacov commented Apr 7, 2020

added RollingInterval feature in order to generate new log file every single hour.

RollingInterval is the number of seconds before rotating to a new log file.
the old log files will be deleted by the MaxAge & MaxBackups properties as usual. if the rolling interval is 0 the feature is off, default is 0.

@oryaacov
Copy link
Author

@glaslos Hey:) this is actually a feature that we needed in few project. any chance to review the PR, so we won't used the forked branch?
thank you :)

lumberjack.go Outdated Show resolved Hide resolved
lumberjack.go Outdated Show resolved Hide resolved
lumberjack.go Outdated Show resolved Hide resolved
lumberjack.go Outdated Show resolved Hide resolved
lumberjack_test.go Outdated Show resolved Hide resolved
changed intervalExceeded to exceedsRollingInterval
changed TestRollingInterval to set createdAt 2 seconds backward instead of using time.After
fixed comments
Copy link
Author

@oryaacov oryaacov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@glaslos Thank you for your comments. I fixed everything at this commit.

Copy link
Contributor

@glaslos glaslos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@glaslos
Copy link
Contributor

glaslos commented Oct 29, 2020

@natefinch what do you think?

@natefinch
Copy link
Owner

So here's the thing... the whole point of rolling a log file is to avoid filling up your disk. Rolling on a time interval doesn't do that. You could have a script kiddie or runaway process that spams the logs... and you could quickly run out of disk space if you wait to roll once a day or once an hour.

This is the main reason why I have resisted adding periodic rolling. What's the use case here?

@glaslos
Copy link
Contributor

glaslos commented Oct 29, 2020

@natefinch it's not replacing any of the existing measures, so anything spamming would still trigger the MaxSize and MaxBackups. If I interpret it correctly, this solves a use case where you want for example the log to roll over every 24h.

@oryaacov
Copy link
Author

@natefinch as @glaslos said it won't fill up the disk or create unnecessary spamming since the rolling mechanism still exists as it currently is (MaxSize and MaxBackups will still work as usual).
The use case here is if you want to seperate your logs files into hourly/daily files but still keeping the rolling mechanism.
It most useful when some person (for example an IT person who wish to get a log from remote server) or a third party software wish to get a specific hour/day log file, without the need to take a file and extract the required logs from it.

@natefinch
Copy link
Owner

I think we should roll this (heh) into a v3 version of lumberjack. See here: #115

@glaslos
Copy link
Contributor

glaslos commented Oct 30, 2020

Time to make a new branch then? :)

@oryaacov
Copy link
Author

please let me know if there is anything that I could do, I'll be more than glad to help :)

@phuslu
Copy link

phuslu commented Dec 7, 2020

rolling interval is hard, we must face to potential goroutine leakage and race condition, maybe it's not a bug finally, it's a wrong design.

@phuslu
Copy link

phuslu commented Dec 7, 2020

And user probably will not be satisfied just rolling by every x seconds , users usually want a cron syntax rotation.
So, does we should support the cron ? seems that answer is No.

@Navgeet
Copy link

Navgeet commented Aug 4, 2021

I can vouch for this feature as well. A simple use case is syncing the logs to s3. In this case, not only do you want to rotate by size so as to avoid filling up disk, you also want to rotate by time so that recent logs are synced and not kept forever.

That said, this implementation rotates on a write and not asynchronously, so it's suboptimal for the above use case.

@Jacob-graham
Copy link

Hey, that is exactly what we need!

Is there any time estimation when it is going to be merged into master?

@oryaacov
Copy link
Author

oryaacov commented Jan 6, 2022

We will also be glad to use the original repository instead of my fork.

@natefinch because that it's a fully tested side feature that is not depended on or required by any other part of the project, I think that it's ready to be merged into master and not wait to version 3,

@wanderersean
Copy link

@oryaacov haha, this commit is what we are searching for! Besides, could you add the ability to rotate files exactly on the hour, like "08:00:00" or "12:00:00". I would like to rotate a file daily on "00:00:00" instead of 24 hours after the setup. Thank you in advance for your help.

@oryaacov
Copy link
Author

oryaacov commented Feb 6, 2023

@natefinch can we merge this commit?

@natefinch
Copy link
Owner

Yes, I've come around on it, mostly because there is a use case that I hadn't considered before. You may not want to keep logs beyond a certain date, as a data retention window. MaxAge will sorta do that, but it only checks when you rotate, so if you happen to not rotate for too long, you'll end up keeping old logs longer than you wanted to. Adding a rolling interval ensures that you can be sure that you'll age out old logs. There's probably a better way to do it, too, but this is a valid feature regardless.

Lemme fix whatever bug is screwing up go get today, and then this goes in.

@oryaacov
Copy link
Author

oryaacov commented Feb 7, 2023

@natefinch sure, thank you.
let me know if there is anyway I can help.

@oryaacov
Copy link
Author

@natefinch hey, can we merge?

@RonaldinhoL
Copy link

why dose it still not be merged

@Jacob22g
Copy link

Jacob22g commented May 29, 2023

Were still waiting for it as well
Can we please merge it?

@oryaacov
Copy link
Author

@natefinch may you please merge/close the PR?

@Hixon10
Copy link

Hixon10 commented Feb 17, 2024

So here's the thing... the whole point of rolling a log file is to avoid filling up your disk. Rolling on a time interval doesn't do that. You could have a script kiddie or runaway process that spams the logs... and you could quickly run out of disk space if you wait to roll once a day or once an hour.

This is the main reason why I have resisted adding periodic rolling. What's the use case here?

@natefinch I could tell about my use case. I have a background task, which sends backup-ed log files to S3. So, I want to send a file every 5 minutes, even if it is just a few records (otherwise, I could lose logs for more, than 5 minutes).

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

Successfully merging this pull request may close these issues.

10 participants