50 $this->nextRotation = new \DateTime(
'tomorrow');
51 $this->filenameFormat =
'{filename}-{date}';
52 $this->dateFormat =
'Y-m-d';
64 if (
true === $this->mustRotate) {
76 if (
true === $this->mustRotate) {
83 if (!preg_match(
'{^Y(([/_.-]?m)([/_.-]?d)?)?$}',
$dateFormat)) {
85 'Invalid date format - format must be one of '.
86 'RotatingFileHandler::FILE_PER_DAY ("Y-m-d"), RotatingFileHandler::FILE_PER_MONTH ("Y-m") '.
87 'or RotatingFileHandler::FILE_PER_YEAR ("Y"), or you can set one of the '.
88 'date formats using slashes, underscores and/or dots instead of dashes.',
94 'Invalid filename format - format should contain at least `{date}`, because otherwise rotating is impossible.',
107 protected function write(array $record)
110 if (null === $this->mustRotate) {
111 $this->mustRotate = !file_exists($this->url);
114 if ($this->nextRotation < $record[
'datetime']) {
115 $this->mustRotate =
true;
129 $this->nextRotation = new \DateTime(
'tomorrow');
132 if (0 === $this->maxFiles) {
137 if ($this->maxFiles >= count($logFiles)) {
143 usort($logFiles,
function ($a, $b) {
144 return strcmp($b, $a);
147 foreach (array_slice($logFiles, $this->maxFiles) as $file) {
148 if (is_writable($file)) {
151 set_error_handler(
function ($errno, $errstr, $errfile, $errline) {});
153 restore_error_handler();
157 $this->mustRotate =
false;
162 $fileInfo = pathinfo($this->filename);
163 $timedFilename = str_replace(
164 array(
'{filename}',
'{date}'),
165 array($fileInfo[
'filename'], date($this->dateFormat)),
166 $fileInfo[
'dirname'] .
'/' . $this->filenameFormat
169 if (!empty($fileInfo[
'extension'])) {
170 $timedFilename .=
'.'.$fileInfo[
'extension'];
173 return $timedFilename;
178 $fileInfo = pathinfo($this->filename);
180 array(
'{filename}',
'{date}'),
181 array($fileInfo[
'filename'],
'[0-9][0-9][0-9][0-9]*'),
182 $fileInfo[
'dirname'] .
'/' . $this->filenameFormat
184 if (!empty($fileInfo[
'extension'])) {
185 $glob .=
'.'.$fileInfo[
'extension'];
const DEBUG
Detailed debug information.
Stores logs to files that are rotated every day and a limited number of files are kept...
__construct($filename, $maxFiles=0, $level=Logger::DEBUG, $bubble=true, $filePermission=null, $useLocking=false)
rotate()
Rotates the files.
Stores to any stream resource.
setFilenameFormat($filenameFormat, $dateFormat)