mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-08 06:06:40 +02:00
Avoid using GlobIterator since it seems to trip up open_basedir restrictions, fixes #204
This commit is contained in:
@@ -93,22 +93,20 @@ class RotatingFileHandler extends StreamHandler
|
||||
if (!empty($fileInfo['extension'])) {
|
||||
$glob .= '.'.$fileInfo['extension'];
|
||||
}
|
||||
$iterator = new \GlobIterator($glob);
|
||||
$count = $iterator->count();
|
||||
if ($this->maxFiles >= $count) {
|
||||
$logFiles = glob($glob);
|
||||
if ($this->maxFiles >= count($logFiles)) {
|
||||
// no files to remove
|
||||
return;
|
||||
}
|
||||
|
||||
// Sorting the files by name to remove the older ones
|
||||
$array = iterator_to_array($iterator);
|
||||
usort($array, function($a, $b) {
|
||||
return strcmp($b->getFilename(), $a->getFilename());
|
||||
usort($logFiles, function($a, $b) {
|
||||
return strcmp($b, $a);
|
||||
});
|
||||
|
||||
foreach (array_slice($array, $this->maxFiles) as $file) {
|
||||
if ($file->isWritable()) {
|
||||
unlink($file->getRealPath());
|
||||
foreach (array_slice($logFiles, $this->maxFiles) as $file) {
|
||||
if (is_writable($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user