Logging is too noisy by default

Created on 28 June 2023, 12 months ago
Updated 5 December 2023, 7 months ago

Problem/Motivation

#3317482: Add logging support to the backend client β†’ adds a lot of noisy logging.

#3324264: Add setting to turn off logging β†’ documents how to turn it off if you're using Monolog - I'm not, so is there any other way of turning this down to be less noisy by default? I think most users don't need this level of logging out of the box.

Steps to reproduce

Enable the module and do some searches.

Proposed resolution

Add a configuration option or documentation.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Closed: won't fix

Version

2.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom longwave UK

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @longwave
  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    Just following up here that a temporary fix for this is to add this to services.yml:

    services:
      logger.channel.search_api_opensearch_client:
        class: Psr\Log\NullLogger
    

    This prevents any logging from the client at all, but ideally it would be possible to limit it by severity somehow so errors are still logged, but not all the debug noise.

  • πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia

    I think we should create a new logger channel that we pass to the backend library. At least that way we can log the module code, and configure the backend library code separately.

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

    Here's a LoggerChannel subclass that I wrote a couple weeks ago to for this. It drops all INFO and DEBUG logs.

    
    namespace Drupal\opensearch_log_silencer;
    
    use Drupal\Core\Logger\LoggerChannel;
    use Drupal\Core\Logger\RfcLogLevel;
    
    /**
     * Logger to drop all INFO and DEBUG entries.
     */
    class NoDebugLogger extends LoggerChannel {
    
      /**
       * {@inheritdoc}
       */
      public function log($level, $message, array $context = []) {
        if (is_string($level)) {
          // Convert to integer equivalent for consistency with RFC 5424.
          $level = $this->levelTranslation[$level];
        }
        // Drop all levels less severe than NOTICE. This currently means no INFO or
        // DEBUG log entries.
        if ($level > RfcLogLevel::NOTICE) {
          return;
        }
        parent::log($level, $message, $context);
      }
    
    }
    

    It would be nice if something like this were integrated into the module.

  • Open on Drupal.org β†’
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 5.7
    last update 11 months ago
    Not currently mergeable.
  • @kimpepper opened merge request.
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 5.7
    last update 11 months ago
    49 pass
  • Status changed to Needs review 11 months ago
  • πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia

    Here's a MR that adds a separate logger channel for the library Client. You can configure that to be a NULL logger if you want via Symfony service overloading, or monolog if you use that.

  • Status changed to Needs work 11 months ago
  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    @kim.pepper you already have logger.channel.search_api_opensearch for module logging and logger.channel.search_api_opensearch_client for client logging - the latter is only used in the same place this MR touches.

    #4 is a nice idea as I think I would like to see errors from the client, but multiple lines of debug for every query run are not necessary.

  • Status changed to Postponed: needs info 11 months ago
  • πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia

    Ah yes! Apologies.

    I think filtering log messages based on level is outside the scope of this module. As mentioned before, Monolog can do this for you. If you want to stick to core dependencies and PSR Logger, you only have the NullLogger to help you.

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

    @kim.pepper: If you are willing to reconsider, this patch allows configuring the logging threshold for the OpenSearch client.

    This patch also solves one additional problem. Drupal's logger instances expect the keys of the $context array to be prefixed placeholders which are also present in the $message. PSR-3 makes no such requirements, and therefore the OpenSearch client places vital pieces of debug information in the $context without adding placeholders for them. This custom LoggerChannel implementation prefixes the context keys with '@' and adds them to the $message to be logged.

    Without this last detail, the debug messages generated by the OpenSearch client are almost entirely useless.

  • Status changed to Needs review 11 months ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 5.7
    last update 11 months ago
    41 pass, 6 fail
  • πŸ‡ΊπŸ‡ΈUnited States daniel_j
  • Status changed to Needs work 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States daniel_j

    Bah, the last patch had a careless bug in it.

  • Status changed to Closed: won't fix 11 months ago
  • πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia

    As I've said already, managing logs, filtering by level etc, is outside the responsibilities of this module. You are free to change out the logger to what ever contrib or custom code you want, but it's not something I will add to the module.

  • πŸ‡³πŸ‡ΏNew Zealand dieuwe Auckland, NZ

    In case anyone comes here and tries to implement a fix to reduce log noise (especially on a busy site that still uses db logging), I had a lot of trouble trying to override the service in a way that held.

    You can adapt the code from comment #4 in a custom module, noting that there has been a change to the log method definition:

      public function log($level, string|\Stringable $message, array $context = []): void {
    

    Then in your custom module's services file:

    services:
      logger.channel.search_api_opensearch_no_debug:
        decorates: logger.channel.search_api_opensearch_client
        class: Drupal\my_module\OpenSearchNoDebugLogger
        arguments: [ 'search_api_opensearch_client', '@request_stack', '@current_user' ]

    I've never had to use Symfony's decorates parameter before but it is really cool. (I struggled to find any Drupal-specific documentation on overriding services that really pointed me in the right direction.)

Production build 0.69.0 2024