Suppressing log channels does not queued messages

Created on 15 June 2025, 4 months ago

Problem/Motivation

Suppressing log channels by returning a NullLogger prevents log entries from being created for those messages, but the messages themselves are still queued internally by Drupal’s logger system. Because these queued messages are retained while suppression is active, when the module is disabled or removed, all of those queued messages are processed and result in a sudden burst of log entries for the previously suppressed channels. This causes a “log flood” of delayed log messages upon the next request.

Steps to reproduce

  • Enable the suppress_logs module and configure it to suppress the "rest" channel (or any specific channel).
  • Trigger log messages for the suppressed channel.
  • Disable or uninstall the suppress_logs module.
  • Refresh the site or perform any page request.
  • Observe a sudden flood of previously suppressed log messages appearing in the logs.

Proposed resolution

Introduce an ImmediateNullLogger class that implements Psr\Log\LoggerInterface and immediately discards all log messages without queuing them. This logger would be returned for suppressed channels to prevent message accumulation and delayed flushing.

Example implementation:

<?php

namespace Drupal\suppress_logs;

use Psr\Log\LoggerInterface;
use Stringable;

class ImmediateNullLogger implements LoggerInterface {

  public function emergency(string|Stringable $message, array $context = []): void {}
  public function alert(string|Stringable $message, array $context = []): void {}
  public function critical(string|Stringable $message, array $context = []): void {}
  public function error(string|Stringable $message, array $context = []): void {}
  public function warning(string|Stringable $message, array $context = []): void {}
  public function notice(string|Stringable $message, array $context = []): void {}
  public function info(string|Stringable $message, array $context = []): void {}
  public function debug(string|Stringable $message, array $context = []): void {}

  public function log(mixed $level, string|Stringable $message, array $context = []): void {
    // Discard message immediately without queuing.
  }
}

Remaining tasks

Implement the proposed solution or investigate another method to prevent the queuing of suppressed messages.

User interface changes

None

API changes

None

Data model changes

None

Feature request
Status

Active

Version

1.0

Component

Code

Created by

🇺🇸United States johnhanley

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

Comments & Activities

Production build 0.71.5 2024