Problem/Motivation
Hello everyone,
Recently in one of our projects we had an issue where the config_log table had a huge size. The issue was not caused by the config log module but it led us to discover that the module does not have a way to delete logs in the config_log table. We had to implement such a solution so I'm leaving here the patch in case it could help anyone.
Proposed resolution
Add a solution similar to what the dblog module uses. We added a new configuration to the config page where the user can select how many logs they would want to store. Based on that we also added a cron job to delete the logs in the config_log table. Nothing was done on the logs stored on the watchdog table.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | add-retention-policy-to-logs-3547908-3.patch | 2.54 KB | yazanmajadba |
| #5 | add-retention-policy-to-logs-3547908-5.patch | 3.52 KB | nsalves |
| #2 | add-retention-policy-to-logs-3547908-2.patch | 2.6 KB | nsalves |
Issue fork config_log-3547908
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
nsalves commentedComment #3
nsalves commentedComment #4
nagy.balint commentedThank you for the patch!
I have the following feedback:
1. We use ConfigLogDatabaseSubscriber::$type to define "custom" so the line
+ ':input[name="log_destination[custom]"]' => ['checked' => TRUE],should also use that.
And likely below in the getValue as well.
2. $config_log_conf->get('logs_to_keep') might be problematic if a site updates to this version and the config does not exist. It would be better to add a fallback value to that.
3. config_log.schema.yml and config_log.settings.yml is missing the new config item.
4. If logs_to_keep is int type, then it might be better to store a 0 in the else instead of $config->set('logs_to_keep', '');
Comment #5
nsalves commentedHey nagy.balint, thanks for the feedback. Here's a new version of the patch where I believe I addressed all the feedback. Thanks !
Comment #6
nsalves commentedComment #7
nagy.balint commentedHi!
Thank you!
Can you reroll the patch for the 4.x branch? as that is the main supported branch?
Also in the cron we might need to do the same
$row_limit = \Drupal::config('config_log.settings')->get('logs_to_keep');
to add ?: 0
even though NULL > 0 i think is false, would be better.
Comment #10
yazanmajadba commentedHere’s the updated patch for the 4.x branch.
https://git.drupalcode.org/project/config_log/-/merge_requests/24.patch
Comment #11
nagy.balint commentedHmm,
The add-retention-policy-to-logs-3547908-5.patch in #5 already had a cron which was simpler, you have not found it good enough?
Comment #12
yazanmajadba commentedThe patch is great, but it doesn't work with 4.x.
I rererolled the patch to work with 4.x and followed your instructions on #7
Comment #14
nagy.balint commentedThank You!
The two patches have different cron, but it seems the second one is better.