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

Glog should delete old log files automaticly #423

Closed
DinoStray opened this issue Jan 27, 2019 · 8 comments
Closed

Glog should delete old log files automaticly #423

DinoStray opened this issue Jan 27, 2019 · 8 comments

Comments

@DinoStray
Copy link

For example, I wanna keep log files for only 7 days.
Then the glog should delete all the log files which last modify time before 7 days.

@aesophor
Copy link
Contributor

aesophor commented Feb 7, 2019

I think a cron job can do it

This deletes the logs produced by glog under /tmp that are last modified 7 days ago.

$ find /tmp -name 'YourProjectName.*' -mtime +7 -delete

Then $ crontab -e and add this line to run it daily at 00:00 AM

0 0 * * * find /tmp -name 'YourProjectName.*' -mtime +7 -delete

@DinoStray
Copy link
Author

I think a cron job can do it

This deletes the logs produced by glog under /tmp that are last modified 7 days ago.

$ find /tmp -name 'YourProjectName.*' -mtime +7 -delete

Then $ crontab -e and add this line to run it daily at 00:00 AM

0 0 * * * find /tmp -name 'YourProjectName.*' -mtime +7 -delete

But If I use docker or k8s, there is no crontab.
Clean old logs should done by the glog itself

@aesophor
Copy link
Contributor

aesophor commented Feb 17, 2019

@DinoStray I've written the code to automatically remove old logs, but they are not yet integrated into the original codebase.

@sergiud I'm not sure when to call it. Calling it at the end of LogFileObject::FlushUnlocked() seems really unwise, since that scans for old logs too frequently. Could you please help me with this? Thank you!

@letrthong
Copy link

letrthong commented Feb 27, 2019

I read your code but Raspberry doesn't have real time clock so can not get correct timestamp. Please check the case

@letrthong
Copy link

i wrote code to limit maximum size of all files about 3M which is running on raspberry pi.

@aesophor
Copy link
Contributor

aesophor commented Aug 21, 2019

@DinoStray I tried to implement this and it works on my linux box! 😄 (gentoo-4.19.66) But I haven't tested it on Windows, I'll do it once I have spare time.

Edit: Now it works on both linux and windows.


Simply add this to your project to enable log cleaner, it is disabled by default. Once enabled, it will automatically remove old logs that are last modified over 3 days. Only the logs produced by the project which glog is linked in will be removed, logs from other projects won't be touched.

google::EnableLogCleaner(3);

You can also disable it at anytime by calling

google::DisableLogCleaner();

Please see here for technical details.
#432 (comment)

@aesophor
Copy link
Contributor

aesophor commented Aug 21, 2019

I read your code but Raspberry doesn't have real time clock so can not get correct timestamp. Please check the case

So there's no way get the timestamp for a file on Raspberry pi? I'll try to see if I there are other ways.

Edit: Sorry, I mean get current time, not file's timestamp.

@aesophor
Copy link
Contributor

aesophor commented Nov 5, 2019

@DinoStray I think you could close this now

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

No branches or pull requests

4 participants