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

Feature request: Have an option to compress log files after their rotation #322

Open
nilstoedtmann opened this issue Nov 25, 2013 · 48 comments
Labels

Comments

@nilstoedtmann
Copy link

I know that there are tools like logrotate that can do rotate-and-compress [1]. But logrotate cannot enforce {streamname} _logfile _maxbytes just-in-time [2]. Therefore i preferred supervisor to handle the rotation.


[1] https://lists.supervisord.org/pipermail/supervisor-users/2010-November/000751.html
[2] I have processes that occasionally, e.g. if certain errors occur, fill logs rapidly. By the time logrotate runs next time, the limited storage on my embedded system is already full.

@arabus4chip
Copy link

+1

And even better: with configurable compress program and extension , like gzip/.gz, bzip2/.bz2, xz/.xz.

@DanMauger
Copy link

+1 - Would definitely like to see this

@vahdani
Copy link

vahdani commented Jul 6, 2014

+1

1 similar comment
@fmela
Copy link

fmela commented Jul 23, 2014

+1

@vltr
Copy link

vltr commented Sep 11, 2014

+1 oh yes!

@mwf
Copy link

mwf commented Oct 3, 2014

+1, it would be great!

@mpyrev
Copy link

mpyrev commented Dec 15, 2014

+1

4 similar comments
@danslimmon
Copy link

+1

@miliauskaite
Copy link

+1

@harai
Copy link

harai commented Mar 6, 2015

+1

@analytically
Copy link

+1

@elsmorian
Copy link

+1

3 similar comments
@cbarraford
Copy link

+1

@cdesales
Copy link

+1

@xpzouying
Copy link

+1

@romainfun
Copy link

Note : Recent versions of logrotate include a maxsize option

@nilstoedtmann
Copy link
Author

logrotate is not watching logs continuously. By the time logrotate gets around to check for [max]size, the logs might have already filled up the disk (as mentioned in the OP).

@fabrizioficci
Copy link

+1

@sunkencity
Copy link

How about having an option to replacing the rotation scheme ending number with a postfix of date_from-date_to?

/my_process.log
/my_process.2016-04-13_04.30.00-2016-04-14_07.59.59.log
/my_process.2016-04-14_08.00.00-2016-04-14_12.00.00.log

Pros:

  • easy to know in which logfile to look for older data.
  • easy to add cron job to compress
  • easy to add cron job to archive
  • each logfile has a unique name
  • still easy to delete the oldest file
  • no contention over logfiles being rotated while taking a backup
  • can use supervisord without logrotate and thus not being prone to lose data while logs are rotated.

@sunkencity
Copy link

If that is a way forward that is acceptable as a patch. I'd be happy to implement it.

@keen99
Copy link

keen99 commented Jul 13, 2016

+1 - rather surprised (but the again, not considering issue with logfile ownership) that there's no option to compress rotated logs.

@noxdafox
Copy link

An implementation effort was made long ago #619 but it was not good enough.

Main issue is that Supervisor is implemented on top of an event-loop and file compression might take long time making Supervisor missing important events.

@EwaldvanGeffen
Copy link

-1: supervisor has it's features and logrotate has it's own. Let's not duplicate features, I would even prefer for supervisord to notify logrotate to start running.

@nilstoedtmann
Copy link
Author

nilstoedtmann commented Jul 28, 2016

Well supervisor has already duplicated the main feature: rotation. This ticket is to add compression to the already existing rotation.

But in the end I don't really care whether the actual rotation and/or compression is done by supervisor itself, or by some other software. It is vital though that the rotation happens immediately when the logfile's size reaches its threshold.

So how would this look like? I guess supervisor should the not do any rotation (good luck having supervisor rotate, and logrotate only compress. I tried it, and it's a bad idea). There would be a new supervisor directive rotation_command = /usr/sbin/logrotate /etc/supervisor/logrotate.conf, and when *_logfile_maxbytes is hit, then instead of the internal rotation, the external rotation_command is executed. The logrotate.conf in question would have a size directive that is equal (or slightly smaller, to be on the safe side) than *_logfile_maxbytes. Finally there should be something like postrotate kill -USR2 $(cat /var/run/supervisord.pid) to tell supervisor to re-open its logfiles.

I have to admit this feels slightly cumbersome.

@vltr
Copy link

vltr commented Jul 28, 2016

@EwaldvanGeffen I totally agree with you. Some time ago I voted a +1 in this same issue, but now I think that tools like supervisor should follow the "unix philosophy", plain and simple: do one thing and do it right; to be a part of the process and not the whole process. Logrotate does provide everything requested in here. Let supervisor do what it does best. Let logrotate do what it does best. For FAQ / RTFM sakes, it is feasible to provide an extra chapter or tutorial or how-to to connect both and that's it. Not only logrotator, but there are a couple of "cloud log tools" around that could be fed by supervisor - like Graphite, as an simple example.

The only point that matters here is what @nilstoedtmann stated:

But in the end I don't really care whether the actual rotation and/or compression is done by supervisor itself, or by some other software. It is vital though that the rotation happens immediately when the logfile's size reaches its threshold.

If supervisor guarantees that, I think this issue (and many others) would be satisfied. The idea to set your own rotation settings, also described by @nilstoedtmann, looks like an entry point for this, IMHO.

Well, that's just my 2 cents here 🙈

My best regards,
Richard.

@ioandev
Copy link

ioandev commented Feb 8, 2017

+1

3 similar comments
@bezgubov
Copy link

+1

@rampmaster
Copy link

+1

@vikumar-ciena
Copy link

+1

@jonathanozvision
Copy link

+1

@timabbott
Copy link

Is it possible to configure logrotate to just do the compression part with supervisor doing the log rotation?

I don't see a clean way to do that, so it seems like the behavior most users actually want here is impossible with just combining supervisord as it stands and logrotate.

@esabol
Copy link

esabol commented Apr 5, 2018

+1

5 similar comments
@uda
Copy link

uda commented May 1, 2018

+1

@NickStallman
Copy link

+1

@cludokdrewicz
Copy link

+1

@d2-d2
Copy link

d2-d2 commented Sep 25, 2018

+1

@zacksleo
Copy link

+1

@mristin
Copy link

mristin commented Nov 3, 2018

@vltr Could you please add to supervisord documentation how logrotator and supervisor could be coupled? Wouldn't there be problems with race conditions?

@vltr
Copy link

vltr commented Nov 5, 2018

@mristin thanks for bringing my attention to this. I have used supervisor with logrotator some time ago (years) and I don't remember being caught on any race conditions; but I do remember setting some config parameters into logrotator to mitigate the possibility. I don't have any access to this configs anymore since I left the company I used this setup for quite some time now. Sorry for let you without a proper answer on this 😕

@roens
Copy link

roens commented Feb 5, 2019

Perhaps this would be a useful workaround for the lack of a compression option of rotated log files in supervisord?

@esabol
Copy link

esabol commented Feb 5, 2019

Perhaps this would be a useful workaround for the lack of a compression option of rotated log files in supervisord?

Maybe my version of supervisord is old or something, but this would actually break supervisord’s log rotation in my experience.

@nilstoedtmann
Copy link
Author

Perhaps this would be a useful workaround for the lack of a compression option of rotated log files in supervisord?

How does this behave when supervisor's rotation and the (potentially slow) cron compression overlap? I smell race conditions.

@mator
Copy link

mator commented Apr 26, 2021

can we have at least (simple) subprocess implementation first to fix the issue with compression of old log files, based on PR #619 (@noxdafox), instead of waiting indefinitely for "a proper" fix with eventlistener?

i believe, subprocess implementation would fix issue for 99.9% of people voted in this issue.

thanks

@rrauenza
Copy link

rrauenza commented May 3, 2021

can we have at least (simple) subprocess implementation first to fix the issue with compression of old log files, based on PR #619 (@noxdafox), instead of waiting indefinitely for "a proper" fix with eventlistener?

i believe, subprocess implementation would fix issue for 99.9% of people voted in this issue.

I'm confused why that other proposed implementation uses tar to compress multiple (I didn't dig into the PR), but could this also be done asynchronously in threading[1] or even better multiprocessing?

[1] yeah, the GIL, but we'd be doing I/O, and maybe supervisord can handle the timeslice sharing anyway since it isn't CPU intensive?

@oldcai
Copy link

oldcai commented Nov 5, 2021

can we have at least (simple) subprocess implementation first to fix the issue with compression of old log files, based on PR #619 (@noxdafox), instead of waiting indefinitely for "a proper" fix with eventlistener?
i believe, subprocess implementation would fix issue for 99.9% of people voted in this issue.

I'm confused why that other proposed implementation uses tar to compress multiple (I didn't dig into the PR), but could this also be done asynchronously in threading[1] or even better multiprocessing?

[1] yeah, the GIL, but we'd be doing I/O, and maybe supervisord can handle the timeslice sharing anyway since it isn't CPU intensive?

I'll provide a perspective in the shoes of a mountainous person: we can kill a subprocess safely but not a thread.

Plus, this feature request had been there for almost a decade.

@oldcai
Copy link

oldcai commented Nov 5, 2021

In my opinion, if the log rotation function is not complete, it shouldn't be enabled by default and just depend on logrotate. This could decrease the confusion.

@mator
Copy link

mator commented Nov 5, 2021

Is someone (developer) brave enough to close this issue as 'DECLINED' , than keeping issue open for 10 years long?!? Just tell people that there's no way to compress logs, logrotate does not supported, in-application compression is not supported, resistance is futile. Thanks.

@timabbott
Copy link

timabbott commented Nov 5, 2021 via email

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

Successfully merging a pull request may close this issue.