mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-24 13:52:53 +02:00
Optimize rotation so it's only done once per day at most
This commit is contained in:
@@ -23,6 +23,7 @@ class RotatingFileHandler extends StreamHandler
|
|||||||
{
|
{
|
||||||
protected $filename;
|
protected $filename;
|
||||||
protected $maxFiles;
|
protected $maxFiles;
|
||||||
|
protected $mustRotate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $filename
|
* @param string $filename
|
||||||
@@ -43,9 +44,26 @@ class RotatingFileHandler extends StreamHandler
|
|||||||
$timedFilename .= '.'.$fileInfo['extension'];
|
$timedFilename .= '.'.$fileInfo['extension'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// disable rotation upfront if files are unlimited
|
||||||
|
if (0 === $this->maxFiles) {
|
||||||
|
$this->mustRotate = false;
|
||||||
|
}
|
||||||
|
|
||||||
parent::__construct($timedFilename, $level, $bubble);
|
parent::__construct($timedFilename, $level, $bubble);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function write(array $record)
|
||||||
|
{
|
||||||
|
// on the first record written, if the log is new, we should rotate (once per day)
|
||||||
|
if (null === $this->mustRotate) {
|
||||||
|
$this->mustRotate = !file_exists($this->url);
|
||||||
|
}
|
||||||
|
return parent::write($record);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the handler.
|
* Closes the handler.
|
||||||
*/
|
*/
|
||||||
@@ -53,7 +71,7 @@ class RotatingFileHandler extends StreamHandler
|
|||||||
{
|
{
|
||||||
parent::close();
|
parent::close();
|
||||||
|
|
||||||
if (0 !== $this->maxFiles) {
|
if (true === $this->mustRotate) {
|
||||||
$this->rotate();
|
$this->rotate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user