- Issue created by @johnhanley
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.
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.
}
}
Implement the proposed solution or investigate another method to prevent the queuing of suppressed messages.
None
None
None
Active
1.0
Code