Monolog glob does not support stream wrappers

Created on 3 January 2025, 4 months ago

Problem/Motivation

The monolog library uses glob to get the logs on the directory, but glob do not support stream wrappers.
Code:

    protected function rotate(): void
    {
...
        // skip GC of old logs if files are unlimited
        if (0 === $this->maxFiles) {
            return;
        }

        $logFiles = glob($this->getGlobPattern());

Issue from PHP: https://github.com/php/php-src/issues/9224
Issue from drupal/monolog: 🐛 maxFiles for logs not working with private:// custom scheme Active
Issue from Seldaek/monolog: https://github.com/Seldaek/monolog/issues/204

Proposed resolution

Alter the getGlobPattern method to use the real path:

  protected function getGlobPattern(): string {
    $pattern = parent::getGlobPattern();
    $file_system = \Drupal::service('file_system');
    // The glob function does not support stream wrappers
    // So the path should be transformed.
    $real_path = $file_system->realpath($pattern);
    return $real_path;
  }
🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇪🇸Spain eduardo morales alberti Spain, 🇪🇺

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024