[GH-ISSUE #1784] glob() not finding the existing log -> Log rotation doesn't delete files #752

Open
opened 2026-03-04 02:17:40 +03:00 by kerem · 1 comment
Owner

Originally created by @Defcon0 on GitHub (Dec 14, 2022).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/1784

Monolog version 1|2|3? it's version 2

Related to https://github.com/Seldaek/monolog/issues/204#issuecomment-19757534

I use the drupal monolog module which is using this monolog library.

In the following line I get an empty array:

https://github.com/Seldaek/monolog/blob/2.8.0/src/Monolog/Handler/RotatingFileHandler.php#L142

for the path "private://logs/debug.log" because glob can't compute the right paths. The files definitely exist. If I replace the path with an absolute one, it works, but then I'd have to adjust the paths for each and every environment which is tedious :-/

Maybe we can think about using something else than glob() here? Or is there something I can do?

See here as well: https://www.drupal.org/project/monolog/issues/3326496

Thanks in advance!

Originally created by @Defcon0 on GitHub (Dec 14, 2022). Original GitHub issue: https://github.com/Seldaek/monolog/issues/1784 Monolog version 1|2|3? it's version 2 Related to https://github.com/Seldaek/monolog/issues/204#issuecomment-19757534 I use the drupal monolog module which is using this monolog library. In the following line I get an empty array: https://github.com/Seldaek/monolog/blob/2.8.0/src/Monolog/Handler/RotatingFileHandler.php#L142 for the path "private://logs/debug.log" because glob can't compute the right paths. The files definitely exist. If I replace the path with an absolute one, it works, but then I'd have to adjust the paths for each and every environment which is tedious :-/ Maybe we can think about using something else than glob() here? Or is there something I can do? See here as well: https://www.drupal.org/project/monolog/issues/3326496 Thanks in advance!
Author
Owner

@Seldaek commented on GitHub (Feb 4, 2023):

OK I see that glob has no support for stream wrappers, that sucks. We'd need to convert glob + getGlobPattern into something like:

$baseDir = $this->computeBaseDir($this->filename);
$directory = new RecursiveDirectoryIterator($baseDir);
$iterator = new RecursiveIteratorIterator($directory);
$regex = new RegexIterator($iterator, $globPattern);

computeBaseDir has to be done with caution tho, if you use something like setFilenameFormat('{date}.log', 'Y/m/d') then you end up with $this->filename being /path/to/log/2023/01/05.log so it shouldn't take the full dirname as base dir, but needs to be smarter about identifying what path is the real base path.

Also would need to make sure there is no open_basedir regression regarding https://github.com/Seldaek/monolog/issues/204 as this failed with the GlobIterator previously. I'm not sure if other directory iterators have similar issues.

All in all sounds like quite a bit of work for a fairly fringe use case so I'm unlikely to spend time on this tbh. Just wrote down as much info as I could if anyone is interested in tackling this.

Otherwise I would recommend using logrotate on prod systems it's usually a better option than RotatingFileHandler IMO.

<!-- gh-comment-id:1416851508 --> @Seldaek commented on GitHub (Feb 4, 2023): OK I see that glob has no support for stream wrappers, that sucks. We'd need to convert glob + getGlobPattern into something like: ``` $baseDir = $this->computeBaseDir($this->filename); $directory = new RecursiveDirectoryIterator($baseDir); $iterator = new RecursiveIteratorIterator($directory); $regex = new RegexIterator($iterator, $globPattern); ``` computeBaseDir has to be done with caution tho, if you use something like `setFilenameFormat('{date}.log', 'Y/m/d')` then you end up with `$this->filename` being `/path/to/log/2023/01/05.log` so it shouldn't take the full dirname as base dir, but needs to be smarter about identifying what path is the real base path. Also would need to make sure there is no open_basedir regression regarding https://github.com/Seldaek/monolog/issues/204 as this failed with the GlobIterator previously. I'm not sure if other directory iterators have similar issues. All in all sounds like quite a bit of work for a fairly fringe use case so I'm unlikely to spend time on this tbh. Just wrote down as much info as I could if anyone is interested in tackling this. Otherwise I would recommend using logrotate on prod systems it's usually a better option than RotatingFileHandler IMO.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/monolog#752
No description provided.