1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-23 17:46:09 +02:00

Add deprecation errors on RotatingFileHandler (#774)

* Add deprecation errors when attempting to set dateFormats of fileFormats that
break the possibility of rotating easily in RotatingFileHandler. Version 2.x
of Monolog will throw `\InvalidArgumentException`s in these cases.
This commit is contained in:
Remon van de Kamp
2016-05-20 20:13:19 +02:00
committed by Jordi Boggiano
parent 96a19ab308
commit 83a24937ba
2 changed files with 140 additions and 10 deletions

View File

@@ -24,6 +24,10 @@ use Monolog\Logger;
*/
class RotatingFileHandler extends StreamHandler
{
const FILE_PER_DAY = 'Y-m-d';
const FILE_PER_MONTH = 'Y-m';
const FILE_PER_YEAR = 'Y';
protected $filename;
protected $maxFiles;
protected $mustRotate;
@@ -64,6 +68,20 @@ class RotatingFileHandler extends StreamHandler
public function setFilenameFormat($filenameFormat, $dateFormat)
{
if (!in_array($dateFormat, array(self::FILE_PER_DAY, self::FILE_PER_MONTH, self::FILE_PER_YEAR))) {
trigger_error(
'Invalid date format - format should be one of '.
'RotatingFileHandler::FILE_PER_DAY, RotatingFileHandler::FILE_PER_MONTH '.
'or RotatingFileHandler::FILE_PER_YEAR.',
E_USER_DEPRECATED
);
}
if (substr_count($filenameFormat, '{date}') === 0) {
trigger_error(
'Invalid filename format - format should contain at least `{date}`, because otherwise rotating is impossible.',
E_USER_DEPRECATED
);
}
$this->filenameFormat = $filenameFormat;
$this->dateFormat = $dateFormat;
$this->url = $this->getTimedFilename();