ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Monolog\Handler\RotatingFileHandler Class Reference

Stores logs to files that are rotated every day and a limited number of files are kept. More...

+ Inheritance diagram for Monolog\Handler\RotatingFileHandler:
+ Collaboration diagram for Monolog\Handler\RotatingFileHandler:

Public Member Functions

 __construct ($filename, $maxFiles=0, $level=Logger::DEBUG, $bubble=true, $filePermission=null, $useLocking=false)
 
 close ()
 {{Closes the handler.This will be called automatically when the object is destroyed}} More...
 
 setFilenameFormat ($filenameFormat, $dateFormat)
 
- Public Member Functions inherited from Monolog\Handler\StreamHandler
 __construct ($stream, $level=Logger::DEBUG, $bubble=true, $filePermission=null, $useLocking=false)
 
 close ()
 {Closes the handler.This will be called automatically when the object is destroyed} More...
 
 getStream ()
 Return the currently active stream if it is open. More...
 
 getUrl ()
 Return the stream URL if it was configured with a URL and not an active resource. More...
 
- Public Member Functions inherited from Monolog\Handler\AbstractProcessingHandler
 handle (array $record)
 {Handles a record.All records may be passed to this method, and the handler should discard those that it does not want to handle.The return value of this function controls the bubbling process of the handler stack. Unless the bubbling is interrupted (by returning true), the Logger class will keep on calling further handlers in the stack with a given log record.
Parameters
array$recordThe record to handle
Returns
Boolean true means that this handler handled the record, and that bubbling is not permitted. false means the record was either not processed or that this handler allows bubbling.
} More...
 
- Public Member Functions inherited from Monolog\Handler\AbstractHandler
 __construct ($level=Logger::DEBUG, $bubble=true)
 
 isHandling (array $record)
 {Checks whether the given record will be handled by this handler.This is mostly done for performance reasons, to avoid calling processors for nothing.Handlers should still check the record levels within handle(), returning false in isHandling() is no guarantee that handle() will not be called, and isHandling() might not be called for a given record.
Parameters
array$recordPartial log record containing only a level key
Returns
Boolean
} More...
 
 handleBatch (array $records)
 {Handles a set of records at once.
Parameters
array$recordsThe records to handle (an array of record arrays)
} More...
 
 close ()
 Closes the handler. More...
 
 pushProcessor ($callback)
 {Adds a processor in the stack.
Parameters
callable$callback
Returns
self
} More...
 
 popProcessor ()
 {Removes the processor on top of the stack and returns it.
Returns
callable
} More...
 
 setFormatter (FormatterInterface $formatter)
 {Sets the formatter.
Parameters
FormatterInterface$formatter
Returns
self
} More...
 
 getFormatter ()
 {Gets the formatter.
Returns
FormatterInterface
} More...
 
 setLevel ($level)
 Sets minimum logging level at which this handler will be triggered. More...
 
 getLevel ()
 Gets minimum logging level at which this handler will be triggered. More...
 
 setBubble ($bubble)
 Sets the bubbling behavior. More...
 
 getBubble ()
 Gets the bubbling behavior. More...
 
 __destruct ()
 
 isHandling (array $record)
 Checks whether the given record will be handled by this handler. More...
 
 handle (array $record)
 Handles a record. More...
 
 handleBatch (array $records)
 Handles a set of records at once. More...
 
 pushProcessor ($callback)
 Adds a processor in the stack. More...
 
 popProcessor ()
 Removes the processor on top of the stack and returns it. More...
 
 setFormatter (FormatterInterface $formatter)
 Sets the formatter. More...
 
 getFormatter ()
 Gets the formatter. More...
 

Data Fields

const FILE_PER_DAY = 'Y-m-d'
 
const FILE_PER_MONTH = 'Y-m'
 
const FILE_PER_YEAR = 'Y'
 

Protected Member Functions

 write (array $record)
 {{Writes the record down to the log of the implementing handler.
Parameters
array$record
Returns
void
}} More...
 
 rotate ()
 Rotates the files. More...
 
 getTimedFilename ()
 
 getGlobPattern ()
 
 write (array $record)
 {Writes the record down to the log of the implementing handler.
Parameters
array$record
Returns
void
} More...
 
- Protected Member Functions inherited from Monolog\Handler\AbstractProcessingHandler
 write (array $record)
 Writes the record down to the log of the implementing handler. More...
 
 processRecord (array $record)
 Processes a record. More...
 
- Protected Member Functions inherited from Monolog\Handler\AbstractHandler
 getDefaultFormatter ()
 Gets the default formatter. More...
 

Protected Attributes

 $filename
 
 $maxFiles
 
 $mustRotate
 
 $nextRotation
 
 $filenameFormat
 
 $dateFormat
 
- Protected Attributes inherited from Monolog\Handler\StreamHandler
 $stream
 
 $url
 
 $filePermission
 
 $useLocking
 
- Protected Attributes inherited from Monolog\Handler\AbstractHandler
 $level = Logger::DEBUG
 
 $bubble = true
 
 $formatter
 
 $processors = array()
 

Detailed Description

Stores logs to files that are rotated every day and a limited number of files are kept.

This rotation is only intended to be used as a workaround. Using logrotate to handle the rotation is strongly encouraged when you can use it.

Author
Christophe Coevoet stof@.nosp@m.notk.nosp@m..org
Jordi Boggiano j.bog.nosp@m.gian.nosp@m.o@sel.nosp@m.d.be

Definition at line 25 of file RotatingFileHandler.php.

Constructor & Destructor Documentation

◆ __construct()

Monolog\Handler\RotatingFileHandler::__construct (   $filename,
  $maxFiles = 0,
  $level = Logger::DEBUG,
  $bubble = true,
  $filePermission = null,
  $useLocking = false 
)
Parameters
string$filename
int$maxFilesThe maximal amount of files to keep (0 means unlimited)
int$levelThe minimum logging level at which this handler will be triggered
Boolean$bubbleWhether the messages that are handled can bubble up the stack or not
int | null$filePermissionOptional file permissions (default (0644) are only for owner read/write)
Boolean$useLockingTry to lock log file before doing any writes

Definition at line 46 of file RotatingFileHandler.php.

47 {
48 $this->filename = $filename;
49 $this->maxFiles = (int) $maxFiles;
50 $this->nextRotation = new \DateTime('tomorrow');
51 $this->filenameFormat = '{filename}-{date}';
52 $this->dateFormat = 'Y-m-d';
53
54 parent::__construct($this->getTimedFilename(), $level, $bubble, $filePermission, $useLocking);
55 }

References Monolog\Handler\AbstractHandler\$bubble, Monolog\Handler\RotatingFileHandler\$filename, Monolog\Handler\StreamHandler\$filePermission, Monolog\Handler\AbstractHandler\$level, Monolog\Handler\RotatingFileHandler\$maxFiles, Monolog\Handler\StreamHandler\$useLocking, and Monolog\Handler\RotatingFileHandler\getTimedFilename().

+ Here is the call graph for this function:

Member Function Documentation

◆ close()

Monolog\Handler\RotatingFileHandler::close ( )

{{Closes the handler.This will be called automatically when the object is destroyed}}

Reimplemented from Monolog\Handler\StreamHandler.

Definition at line 60 of file RotatingFileHandler.php.

61 {
62 parent::close();
63
64 if (true === $this->mustRotate) {
65 $this->rotate();
66 }
67 }

References Monolog\Handler\RotatingFileHandler\rotate().

Referenced by Monolog\Handler\RotatingFileHandler\setFilenameFormat(), and Monolog\Handler\RotatingFileHandler\write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getGlobPattern()

Monolog\Handler\RotatingFileHandler::getGlobPattern ( )
protected

Definition at line 164 of file RotatingFileHandler.php.

165 {
166 $fileInfo = pathinfo($this->filename);
167 $glob = str_replace(
168 array('{filename}', '{date}'),
169 array($fileInfo['filename'], '*'),
170 $fileInfo['dirname'] . '/' . $this->filenameFormat
171 );
172 if (!empty($fileInfo['extension'])) {
173 $glob .= '.'.$fileInfo['extension'];
174 }
175
176 return $glob;
177 }

Referenced by Monolog\Handler\RotatingFileHandler\rotate().

+ Here is the caller graph for this function:

◆ getTimedFilename()

Monolog\Handler\RotatingFileHandler::getTimedFilename ( )
protected

Definition at line 148 of file RotatingFileHandler.php.

149 {
150 $fileInfo = pathinfo($this->filename);
151 $timedFilename = str_replace(
152 array('{filename}', '{date}'),
153 array($fileInfo['filename'], date($this->dateFormat)),
154 $fileInfo['dirname'] . '/' . $this->filenameFormat
155 );
156
157 if (!empty($fileInfo['extension'])) {
158 $timedFilename .= '.'.$fileInfo['extension'];
159 }
160
161 return $timedFilename;
162 }
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())

References date.

Referenced by Monolog\Handler\RotatingFileHandler\__construct(), Monolog\Handler\RotatingFileHandler\rotate(), and Monolog\Handler\RotatingFileHandler\setFilenameFormat().

+ Here is the caller graph for this function:

◆ rotate()

Monolog\Handler\RotatingFileHandler::rotate ( )
protected

Rotates the files.

Definition at line 113 of file RotatingFileHandler.php.

114 {
115 // update filename
116 $this->url = $this->getTimedFilename();
117 $this->nextRotation = new \DateTime('tomorrow');
118
119 // skip GC of old logs if files are unlimited
120 if (0 === $this->maxFiles) {
121 return;
122 }
123
124 $logFiles = glob($this->getGlobPattern());
125 if ($this->maxFiles >= count($logFiles)) {
126 // no files to remove
127 return;
128 }
129
130 // Sorting the files by name to remove the older ones
131 usort($logFiles, function ($a, $b) {
132 return strcmp($b, $a);
133 });
134
135 foreach (array_slice($logFiles, $this->maxFiles) as $file) {
136 if (is_writable($file)) {
137 // suppress errors here as unlink() might fail if two processes
138 // are cleaning up/rotating at the same time
139 set_error_handler(function ($errno, $errstr, $errfile, $errline) {});
140 unlink($file);
141 restore_error_handler();
142 }
143 }
144
145 $this->mustRotate = false;
146 }
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file

References $file, Monolog\Handler\RotatingFileHandler\getGlobPattern(), and Monolog\Handler\RotatingFileHandler\getTimedFilename().

Referenced by Monolog\Handler\RotatingFileHandler\close().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFilenameFormat()

Monolog\Handler\RotatingFileHandler::setFilenameFormat (   $filenameFormat,
  $dateFormat 
)

Definition at line 69 of file RotatingFileHandler.php.

70 {
71 if (!preg_match('{^Y(([/_.-]?m)([/_.-]?d)?)?$}', $dateFormat)) {
72 trigger_error(
73 'Invalid date format - format must be one of '.
74 'RotatingFileHandler::FILE_PER_DAY ("Y-m-d"), RotatingFileHandler::FILE_PER_MONTH ("Y-m") '.
75 'or RotatingFileHandler::FILE_PER_YEAR ("Y"), or you can set one of the '.
76 'date formats using slashes, underscores and/or dots instead of dashes.',
77 E_USER_DEPRECATED
78 );
79 }
80 if (substr_count($filenameFormat, '{date}') === 0) {
81 trigger_error(
82 'Invalid filename format - format should contain at least `{date}`, because otherwise rotating is impossible.',
83 E_USER_DEPRECATED
84 );
85 }
86 $this->filenameFormat = $filenameFormat;
87 $this->dateFormat = $dateFormat;
88 $this->url = $this->getTimedFilename();
89 $this->close();
90 }
close()
{{Closes the handler.This will be called automatically when the object is destroyed}}

References Monolog\Handler\RotatingFileHandler\$dateFormat, Monolog\Handler\RotatingFileHandler\$filenameFormat, Monolog\Handler\RotatingFileHandler\close(), and Monolog\Handler\RotatingFileHandler\getTimedFilename().

+ Here is the call graph for this function:

◆ write()

Monolog\Handler\RotatingFileHandler::write ( array  $record)
protected

{{Writes the record down to the log of the implementing handler.

Parameters
array$record
Returns
void
}}

Reimplemented from Monolog\Handler\StreamHandler.

Definition at line 95 of file RotatingFileHandler.php.

96 {
97 // on the first record written, if the log is new, we should rotate (once per day)
98 if (null === $this->mustRotate) {
99 $this->mustRotate = !file_exists($this->url);
100 }
101
102 if ($this->nextRotation < $record['datetime']) {
103 $this->mustRotate = true;
104 $this->close();
105 }
106
107 parent::write($record);
108 }

References Monolog\Handler\RotatingFileHandler\close().

+ Here is the call graph for this function:

Field Documentation

◆ $dateFormat

Monolog\Handler\RotatingFileHandler::$dateFormat
protected

◆ $filename

Monolog\Handler\RotatingFileHandler::$filename
protected

◆ $filenameFormat

Monolog\Handler\RotatingFileHandler::$filenameFormat
protected

◆ $maxFiles

Monolog\Handler\RotatingFileHandler::$maxFiles
protected

◆ $mustRotate

Monolog\Handler\RotatingFileHandler::$mustRotate
protected

Definition at line 33 of file RotatingFileHandler.php.

◆ $nextRotation

Monolog\Handler\RotatingFileHandler::$nextRotation
protected

Definition at line 34 of file RotatingFileHandler.php.

◆ FILE_PER_DAY

◆ FILE_PER_MONTH

const Monolog\Handler\RotatingFileHandler::FILE_PER_MONTH = 'Y-m'

◆ FILE_PER_YEAR

const Monolog\Handler\RotatingFileHandler::FILE_PER_YEAR = 'Y'

The documentation for this class was generated from the following file: