Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/Monolog/Handler/RotatingFileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
class RotatingFileHandler extends StreamHandler
{
public const FILE_PER_HOUR = 'Y-m-d-H';
public const FILE_PER_DAY = 'Y-m-d';
public const FILE_PER_MONTH = 'Y-m';
public const FILE_PER_YEAR = 'Y';
Expand Down Expand Up @@ -194,29 +195,30 @@ protected function getGlobPattern(): string
$glob = str_replace(
['{filename}', '{date}'],
[$fileInfo['filename'], str_replace(
['Y', 'y', 'm', 'd'],
['[0-9][0-9][0-9][0-9]', '[0-9][0-9]', '[0-9][0-9]', '[0-9][0-9]'],
['Y', 'y', 'm', 'd', 'H'],
['[0-9][0-9][0-9][0-9][0-9]', '[0-9][0-9][0-9][0-9]', '[0-9][0-9]', '[0-9][0-9]', '[0-9][0-9]'],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks borked.. It should just add , '[0-9][0-9]' at the end of the line I think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really stupid mistake ))

$this->dateFormat
)],
($fileInfo['dirname'] ?? '') . '/' . $this->filenameFormat
);
if (isset($fileInfo['extension'])) {
$glob .= '.'.$fileInfo['extension'];
}

return $glob;
}

protected function setDateFormat(string $dateFormat): void
{
if (0 === preg_match('{^[Yy](([/_.-]?m)([/_.-]?d)?)?$}', $dateFormat)) {
if (0 === preg_match('{^[Yy](([/_.-]?m)([/_.-]?d)([/_.-]?H)?)?$}', $dateFormat)) {
throw new InvalidArgumentException(
'Invalid date format - format must be one of '.
'Invalid date format - format must be one of RotatingFileHandler::FILE_PER_HOUR ("Y-m-d-H"), '.
'RotatingFileHandler::FILE_PER_DAY ("Y-m-d"), RotatingFileHandler::FILE_PER_MONTH ("Y-m") '.
'or RotatingFileHandler::FILE_PER_YEAR ("Y"), or you can set one of the '.
'date formats using slashes, underscores and/or dots instead of dashes.'
);
}

$this->dateFormat = $dateFormat;
}

Expand Down
Loading