Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glob() not finding the existing log -> Log rotation doesn't delete files #1784

Open
Defcon0 opened this issue Dec 14, 2022 · 1 comment
Open
Labels
Milestone

Comments

@Defcon0
Copy link

Defcon0 commented Dec 14, 2022

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

Related to #204 (comment)

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!

@Defcon0 Defcon0 added the Bug label Dec 14, 2022
@Defcon0 Defcon0 changed the title https://github.com/Seldaek/monolog/issues/204#issuecomment-19757534 glob() not finding the existing log -> Log rotation doesn't delete files Dec 14, 2022
@Seldaek
Copy link
Owner

Seldaek commented 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 #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.

@Seldaek Seldaek added this to the 2.x milestone Feb 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants