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

Automatically clean up old log files #2609

Open
dgw opened this issue May 26, 2024 · 7 comments
Open

Automatically clean up old log files #2609

dgw opened this issue May 26, 2024 · 7 comments

Comments

@dgw
Copy link
Member

dgw commented May 26, 2024

Requested Feature

Sopel should clean up log files older than some default number of days, with a configuration option to override it.

Problems Solved

Our main Sopel instance started spitting out errors tonight when its jail ran out of disk quota. This feature would prevent similar issues from happening to other users who don't set up an external mechanism to prune logs.

Alternatives

As alluded to above, a cron job or other recurring task could take care of this—at the cost of extra effort from the bot owner.

Notes

The TimedRotatingFileHandler's backupCount option would be a simple way to implement this.

@dgw dgw added the Feature label May 26, 2024
@dgw dgw added this to the 8.1.0 milestone May 26, 2024
@SnoopJ
Copy link
Contributor

SnoopJ commented May 26, 2024 via email

@dgw
Copy link
Member Author

dgw commented May 26, 2024

Sopel already uses TimedRotatingFileHandler to get a new log file each day. It's just not configured to delete old logs, ever, so they build up indefinitely. Our main instance has had raw and debug logs turned on for a long time, which made it a problem much faster than it should ever impact normal use. 😁

@Exirel
Copy link
Contributor

Exirel commented Oct 21, 2024

That's why logrotate exists! We can document its usage for Sopel, the same way we document it to create a service with systemd.

I don't like when a software tries to deal itself with logs, it tends to be messy and never really satisfactory. And on the dev side, it means we would have to deal with the maintenance burden of that.

@dgw
Copy link
Member Author

dgw commented Oct 21, 2024

it tends to be messy and never really satisfactory

What's "messy and never really satisfactory" is defaulting to fill up the user's entire disk if left alone for long enough.

If Sopel shouldn't delete its own old logs because you don't like when software tries to deal with that itself, why are you OK with Sopel creating its own log files for each day?

Requiring the user to set up an external tool is not (IMO) in the spirit of being "simple". Recovering from a full disk also can be not "simple", depending on how Sopel was deployed. Sopel must clean up its own mess, or change to not create the mess in the first place.

@Exirel
Copy link
Contributor

Exirel commented Oct 21, 2024

I strongly disagree with that. First, because rm -rf *.log.* isn't that hard (it's annoying, I've to admit), and second I don't really like that Sopel write logs to files, and I consider it a tradeoff, because for most people this is, indeed, to complex to setup themselves. Beside, Python already deals with log file with the TimedRotatingFileHandler.

That being said, logrotate is pretty standard and quite easy to setup. The configuration file should look like this (I need to check what I used for the filename pattern):

~/.sopel/*.log.* {
  rotate -1
  weekly
  maxage 15
}

This removes log files older than 15 days every week. Can be customized easily to being monthly and older than 30 or 60 days.

@Exirel
Copy link
Contributor

Exirel commented Oct 21, 2024

I can, begrudgingly, accept a config option to use TimedRotatingFileHandler's backupCount option.

@dgw
Copy link
Member Author

dgw commented Oct 21, 2024

I can, begrudgingly, accept a config option to use TimedRotatingFileHandler's backupCount option.

So my original suggestion from May, then? 😁

The TimedRotatingFileHandler's backupCount option would be a simple way to implement this.

Not a terribly involved patch. Hardest part will be deciding what to call the new option (log_max_age?)

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

3 participants