mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-13 16:44:23 +02:00
Simplified RotatingFileHandler a bit
This commit is contained in:
@@ -38,10 +38,8 @@ class RotatingFileHandler extends StreamHandler
|
|||||||
$this->filename = $filename;
|
$this->filename = $filename;
|
||||||
$this->maxFiles = (int) $maxFiles;
|
$this->maxFiles = (int) $maxFiles;
|
||||||
|
|
||||||
|
|
||||||
$date = new \DateTime();
|
|
||||||
$fileInfo = pathinfo($this->filename);
|
$fileInfo = pathinfo($this->filename);
|
||||||
$timedFilename = $fileInfo['dirname'].'/'.$fileInfo['filename'].'-'.$date->format('Y-m-d');
|
$timedFilename = $fileInfo['dirname'].'/'.$fileInfo['filename'].'-'.date('Y-m-d');
|
||||||
if (!empty($fileInfo['extension'])) {
|
if (!empty($fileInfo['extension'])) {
|
||||||
$timedFilename .= '.'.$fileInfo['extension'];
|
$timedFilename .= '.'.$fileInfo['extension'];
|
||||||
}
|
}
|
||||||
@@ -98,15 +96,13 @@ class RotatingFileHandler extends StreamHandler
|
|||||||
// Sorting the files by name to rmeove the older ones
|
// Sorting the files by name to rmeove the older ones
|
||||||
$array = iterator_to_array($iterator);
|
$array = iterator_to_array($iterator);
|
||||||
usort($array, function($a, $b) {
|
usort($array, function($a, $b) {
|
||||||
return strcmp($a->getFilename(), $b->getFilename());
|
return strcmp($b->getFilename(), $a->getFilename());
|
||||||
});
|
});
|
||||||
while ($count > $this->maxFiles) {
|
|
||||||
$file = array_shift($array);
|
foreach (array_slice($array, $this->maxFiles) as $file) {
|
||||||
/* @var $file \SplFileInfo */
|
|
||||||
if ($file->isWritable()) {
|
if ($file->isWritable()) {
|
||||||
unlink($file->getRealPath());
|
unlink($file->getRealPath());
|
||||||
}
|
}
|
||||||
$count--;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user