mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-13 00:24:10 +02:00
Merge remote-tracking branch 'rpkamp/master'
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Monolog\Handler;
|
namespace Monolog\Handler;
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,17 +70,15 @@ class RotatingFileHandler extends StreamHandler
|
|||||||
public function setFilenameFormat($filenameFormat, $dateFormat)
|
public function setFilenameFormat($filenameFormat, $dateFormat)
|
||||||
{
|
{
|
||||||
if (!in_array($dateFormat, array(self::FILE_PER_DAY, self::FILE_PER_MONTH, self::FILE_PER_YEAR))) {
|
if (!in_array($dateFormat, array(self::FILE_PER_DAY, self::FILE_PER_MONTH, self::FILE_PER_YEAR))) {
|
||||||
trigger_error(
|
throw new InvalidArgumentException(
|
||||||
'Invalid date format - format should be one of '.
|
'Invalid date format - format must be one of '.
|
||||||
'RotatingFileHandler::FILE_PER_DAY, RotatingFileHandler::FILE_PER_MONTH '.
|
'RotatingFileHandler::FILE_PER_DAY, RotatingFileHandler::FILE_PER_MONTH '.
|
||||||
'or RotatingFileHandler::FILE_PER_YEAR.',
|
'or RotatingFileHandler::FILE_PER_YEAR.'
|
||||||
E_USER_DEPRECATED
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (substr_count($filenameFormat, '{date}') === 0) {
|
if (substr_count($filenameFormat, '{date}') === 0) {
|
||||||
trigger_error(
|
throw new InvalidArgumentException(
|
||||||
'Invalid filename format - format should contain at least `{date}`, because otherwise rotating is impossible.',
|
'Invalid filename format - format must contain at least `{date}`, because otherwise rotating is impossible.'
|
||||||
E_USER_DEPRECATED
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$this->filenameFormat = $filenameFormat;
|
$this->filenameFormat = $filenameFormat;
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Monolog\Handler;
|
namespace Monolog\Handler;
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
use Monolog\TestCase;
|
use Monolog\TestCase;
|
||||||
use PHPUnit_Framework_Error_Deprecated;
|
use PHPUnit_Framework_Error_Deprecated;
|
||||||
|
|
||||||
@@ -141,15 +142,10 @@ class RotatingFileHandlerTest extends TestCase
|
|||||||
public function testAllowOnlyFixedDefinedDateFormats($dateFormat, $valid)
|
public function testAllowOnlyFixedDefinedDateFormats($dateFormat, $valid)
|
||||||
{
|
{
|
||||||
$handler = new RotatingFileHandler(__DIR__.'/Fixtures/foo.rot', 2);
|
$handler = new RotatingFileHandler(__DIR__.'/Fixtures/foo.rot', 2);
|
||||||
$handler->setFilenameFormat('{filename}-{date}', $dateFormat);
|
|
||||||
if (!$valid) {
|
if (!$valid) {
|
||||||
$this->assertErrorWasTriggered(
|
$this->setExpectedExceptionRegExp(InvalidArgumentException::class, '~^Invalid date format~');
|
||||||
E_USER_DEPRECATED,
|
|
||||||
'Invalid date format - format should be one of '.
|
|
||||||
'RotatingFileHandler::FILE_PER_DAY, RotatingFileHandler::FILE_PER_MONTH '.
|
|
||||||
'or RotatingFileHandler::FILE_PER_YEAR.'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
$handler->setFilenameFormat('{filename}-{date}', $dateFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dateFormatProvider()
|
public function dateFormatProvider()
|
||||||
@@ -169,13 +165,11 @@ class RotatingFileHandlerTest extends TestCase
|
|||||||
public function testDisallowFilenameFormatsWithoutDate($filenameFormat, $valid)
|
public function testDisallowFilenameFormatsWithoutDate($filenameFormat, $valid)
|
||||||
{
|
{
|
||||||
$handler = new RotatingFileHandler(__DIR__.'/Fixtures/foo.rot', 2);
|
$handler = new RotatingFileHandler(__DIR__.'/Fixtures/foo.rot', 2);
|
||||||
$handler->setFilenameFormat($filenameFormat, RotatingFileHandler::FILE_PER_DAY);
|
|
||||||
if (!$valid) {
|
if (!$valid) {
|
||||||
$this->assertErrorWasTriggered(
|
$this->setExpectedExceptionRegExp(InvalidArgumentException::class, '~^Invalid filename format~');
|
||||||
E_USER_DEPRECATED,
|
|
||||||
'Invalid filename format - format should contain at least `{date}`, because otherwise rotating is impossible.'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$handler->setFilenameFormat($filenameFormat, RotatingFileHandler::FILE_PER_DAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function filenameFormatProvider()
|
public function filenameFormatProvider()
|
||||||
|
Reference in New Issue
Block a user