mirror of
https://github.com/Seldaek/monolog.git
synced 2025-10-22 09:06:10 +02:00
Fixing file rotation when similar files are present
This commit is contained in:
committed by
Jordi Boggiano
parent
2893c2b875
commit
5f8783686e
@@ -166,7 +166,7 @@ class RotatingFileHandler extends StreamHandler
|
|||||||
$fileInfo = pathinfo($this->filename);
|
$fileInfo = pathinfo($this->filename);
|
||||||
$glob = str_replace(
|
$glob = str_replace(
|
||||||
array('{filename}', '{date}'),
|
array('{filename}', '{date}'),
|
||||||
array($fileInfo['filename'], '*'),
|
array($fileInfo['filename'], '[0-9][0-9][0-9][0-9]*'),
|
||||||
$fileInfo['dirname'] . '/' . $this->filenameFormat
|
$fileInfo['dirname'] . '/' . $this->filenameFormat
|
||||||
);
|
);
|
||||||
if (!empty($fileInfo['extension'])) {
|
if (!empty($fileInfo['extension'])) {
|
||||||
|
@@ -191,6 +191,40 @@ class RotatingFileHandlerTest extends TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider rotationWhenSimilarFilesExistTests
|
||||||
|
*/
|
||||||
|
public function testRotationWhenSimilarFileNamesExist($dateFormat)
|
||||||
|
{
|
||||||
|
touch($old1 = __DIR__.'/Fixtures/foo-foo-'.date($dateFormat).'.rot');
|
||||||
|
touch($old2 = __DIR__.'/Fixtures/foo-bar-'.date($dateFormat).'.rot');
|
||||||
|
|
||||||
|
$log = __DIR__.'/Fixtures/foo-'.date($dateFormat).'.rot';
|
||||||
|
|
||||||
|
$handler = new RotatingFileHandler(__DIR__.'/Fixtures/foo.rot', 2);
|
||||||
|
$handler->setFormatter($this->getIdentityFormatter());
|
||||||
|
$handler->setFilenameFormat('{filename}-{date}', $dateFormat);
|
||||||
|
$handler->handle($this->getRecord());
|
||||||
|
$handler->close();
|
||||||
|
|
||||||
|
$this->assertTrue(file_exists($log));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rotationWhenSimilarFilesExistTests()
|
||||||
|
{
|
||||||
|
|
||||||
|
return [
|
||||||
|
'Rotation is triggered when the file of the current day is not present but similar exists'
|
||||||
|
=> [RotatingFileHandler::FILE_PER_DAY],
|
||||||
|
|
||||||
|
'Rotation is triggered when the file of the current month is not present but similar exists'
|
||||||
|
=> [RotatingFileHandler::FILE_PER_MONTH],
|
||||||
|
|
||||||
|
'Rotation is triggered when the file of the current year is not present but similar exists'
|
||||||
|
=> [RotatingFileHandler::FILE_PER_YEAR],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function testReuseCurrentFile()
|
public function testReuseCurrentFile()
|
||||||
{
|
{
|
||||||
$log = __DIR__.'/Fixtures/foo-'.date('Y-m-d').'.rot';
|
$log = __DIR__.'/Fixtures/foo-'.date('Y-m-d').'.rot';
|
||||||
|
Reference in New Issue
Block a user