Provide a way to disable creation of database log entries

Created on 13 April 2023, over 1 year ago
Updated 12 August 2024, 4 months ago

Problem/Motivation

The effort of πŸ“Œ Make dblog entities Postponed introduces an interesting problem. If log entries are content, the Database Logging module cannot be uninstalled without deleting the logs first. This is a general rule for all content entries.

The problem is, log entries are not something someones creates on purpose, they are created from external events. So uninstalling the dblog module in a production site can be very difficult if there are a lot of logs created every minute.

Proposed resolution

There are two possible scenarios to fix this problem.

  1. Modify how ContentUninstallerValidator works, to make an exception for dblog entries. Something that makes sense from an UX point of view, but introduces some of potential edge cases in the future that we want to avoid. See why the validator was created on the first place: #2278017: When a content entity type providing module is uninstalled, the entities are not fully deleted, leaving broken reference β†’
  2. Allow to pause the creation of logs entries via the user interface, so logs can be deleted safely.

The goal of this issue is provide a solution for approach 2. Without introducing a performance impact of checking the config values every time a log is created. We don't want to touch the current Drupal\dblog\Logger\Dblog class at all.

Remaining tasks

  1. Add a checkbox in /admin/config/development/logging to pause creation of new logs. Check dblog_form_system_logging_settings_alter to see where put this value.
  2. Save the new configs as part of dblog_logging_settings_submit
  3. Create a new class that implements LoggerInterface but does nothing on the log method. dblog/src/Logger/Disabled.php could be a good place to put this file.
  4. Write a new DblogServiceProvider following these instructions β†’ to swap the logger.dblog service with the one created in step 2 that does not insert a log into the database. Only when the checkbox from step 1 is enabled.
  5. Create a new implementation of hook_requirements that checks $phase == 'runtime' and returns a warning if the logger collection is disabled.
  6. Write test for the disabled logging functionality. Check the core/modules/dblog/tests/src/Kernel/DbLogTest.php as inspiration of how to create log entries, and change the configuration using code.

User interface changes

  • A new checkbox to disable log creation in the dblog ui.
  • A new warning in the status report page if the logger collection is disabled.

API changes

None.

Data model changes

None.

Release notes snippet

✨ Feature request
Status

Needs work

Version

11.0 πŸ”₯

Component
Database LoggingΒ  β†’

Last updated 3 months ago

  • Maintained by
  • πŸ‡¦πŸ‡·Argentina @dagmar
Created by

πŸ‡¦πŸ‡·Argentina dagmar Argentina

Live updates comments and jobs are added and updated live.
  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

  • Usability

    Makes Drupal easier to use. Preferred over UX, D7UX, etc.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Issue created by @dagmar
  • πŸ‡¦πŸ‡·Argentina dagmar Argentina

    Tagging this with Novice β†’ as the instructions to proceed are well defined. I'm here to review and provide guidance if needed.

  • First commit to issue fork.
  • πŸ‡§πŸ‡·Brazil elber Brazil

    I will take a look on it

  • πŸ‡ΈπŸ‡°Slovakia petiar

    Sorry guys, I may have cause some chaos with the 3354081-drupal-11 branch. Anyway, the code for review should be in the 3354081-provide-a-way branch. The only thing missing is the test, which I will write as soon as I will manage to run PHPUnit tests in my lando docker machine.

  • Status changed to Needs review over 1 year ago
  • πŸ‡¦πŸ‡·Argentina dagmar Argentina

    Awesome @petiar! Many thanks.

  • @dagmar opened merge request.
  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Think we will need a CR for the change to the UI.

    https://git.drupalcode.org/project/drupal/-/merge_requests/4375 didn't do a full review since it was in draft.

  • πŸ‡¦πŸ‡·Argentina dagmar Argentina

    There are a few coding standards that needs to be fixed, but those are irrelevant now. The only thing that is not 100% to me right now is how to make the DblogServiceProvider::alter code run as soon the Dblog Form is submitted.

    I'm not sure if \Drupal::service('kernel')->rebuildContainer(); is the way to go, or if there is something less aggressive. I was not able to find something in core that does this already. All the calls to rebuildContainer I found are part of tests.

  • πŸ‡¦πŸ‡·Argentina dagmar Argentina

    I've been trying this today. It seems the approach to alter the service is not actually necessary. Dblog can provide the service using by DblogServiceProvider::register and provide the regular logger only when the config is not available.

    The only example in core I found doing something kind of similar is the Drupal\language\LanguageServiceProvider.

    The logic then would be something like this:

    
    namespace Drupal\dblog;
    
    use Drupal\Core\DependencyInjection\ContainerBuilder;
    use Drupal\Core\DependencyInjection\ServiceProviderBase;
    
    class DblogServiceProvider extends ServiceProviderBase {
    
      public function register(ContainerBuilder $container) {
    
        if (\Drupal::configFactory()->getEditable('dblog.settings')->get('logging_paused')) {
          return;
        }
    
        $container->register('dblog.logger', 'Drupal\dblog\Logger\DbLog')
        // ...
      }
    
    }
    

    \Drupal::configFactory() wont work at this register phase I'm afraid. But again LanguageServiceProvider provides some clues how what to do.

  • Assigned to imustakim
  • πŸ‡¨πŸ‡¦Canada imustakim Canada
  • Issue was unassigned.
  • Status changed to Needs review about 1 year ago
  • πŸ‡¨πŸ‡¦Canada imustakim Canada

    MR updated.
    Please review.

  • Status changed to Needs work about 1 year ago
  • πŸ‡ΈπŸ‡°Slovakia poker10

    Thanks for working on this! Tagging this with Usability tag as there are changes to the UI (new checkbox).

    I would personally prefer to have a Usability review here as well, because the two proposed solutions (see the IS) can be evaluated from different point of views:

    1) as a developer
    I would agree that introducing an exception for dblog entries when uninstalling is not a great thing.

    2) as a website admin
    Currently you can uninstall the module in one click, without need to care about anything. But instead of one click, now you will need to do (at least) two more steps (2 + 3):

    1. Go to the modules uninstall page - you will see that it is not possible to uninstall the module
    2. Go to the dblog module settings and pause logging - the question also is whether users will try to delete the logs first and will need to repeat the steps 2 and 3 again
    3. Delete all dblog entries
    4. Only then you will be able to uninstall the module

    Isn't it possible that it will get too complicated for normal use? I know that uninstalling this module is not something, that is done on a daily basis, but even so.. We can argue that it is needed for all modules using content enties, but I still consider dblog entries as something different like a real content (for me these are just logs).

    The MR is in a draft state (so the tests did not go through) and has codestyle issues, so moving to NW.

  • πŸ‡ΊπŸ‡ΈUnited States mfb San Francisco

    My patch at πŸ› Dependency on config storage causes circular reference in service container Needs review has a pattern that might be useful for dblog module as well: A config subscriber checks if the config changed and if so, invalidates the container.

  • πŸ‡¦πŸ‡·Argentina dagmar Argentina

    @poker10 I think you pointed out some valid inputs. I had the same thoughts as well and this is why I tried to avoid this in the first place while coding πŸ“Œ Make dblog entities Postponed

    Unfortunately I don't see an easy way to avoid this, at least without not touching a lot of content related stuff involved with content deletion.

    The way I see it, dblog entries will be the same than Comments now. If you have a non public site, deleting the logs will be enough to not need to pause them.

    I'm thinking maybe we can avoid this and improve the UX at the same time to allow you to block temporally log entries while you are deleting them.

    I think we can also play with ?redirect=to in the url to make this as simple as possible.

    Eventually most developers will use drush to uninstall dblog, so I think we can provide a patch to make this in one go if we need to.

  • πŸ‡¦πŸ‡·Argentina dagmar Argentina

    Another interesting approach to analyze is the UI provided by the paragraph module. As it allows you to delete the content "on the fly" when deleting a paragraph type.

  • πŸ‡¦πŸ‡·Argentina dagmar Argentina

    Isn't it possible that it will get too complicated for normal use? I know that uninstalling this module is not something, that is done on a daily basis, but even so.. We can argue that it is needed for all modules using content enties, but I still consider dblog entries as something different like a real content (for me these are just logs).

    @poker10 I found a way πŸ“Œ Make dblog entities Postponed to not need this to implement πŸ“Œ Make dblog entities Postponed

    I will keep this issue open in case someone else want to work on this, but the original problem described in the issue is not a problem anymore.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Doesn't seem like a novice level issue

Production build 0.71.5 2024