ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 ()
 {} More...
 
 setFilenameFormat ($filenameFormat, $dateFormat)
 
- Public Member Functions inherited from Monolog\Handler\StreamHandler
 __construct ($stream, $level=Logger::DEBUG, $bubble=true, $filePermission=null, $useLocking=false)
 
 close ()
 {} 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 ()
 

Protected Member Functions

 write (array $record)
 {} More...
 
 rotate ()
 Rotates the files. More...
 
 getTimedFilename ()
 
 getGlobPattern ()
 
- Protected Member Functions inherited from Monolog\Handler\StreamHandler
 write (array $record)
 {} 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
integer$maxFilesThe maximal amount of files to keep (0 means unlimited)
integer$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 42 of file RotatingFileHandler.php.

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().

43  {
44  $this->filename = $filename;
45  $this->maxFiles = (int) $maxFiles;
46  $this->nextRotation = new \DateTime('tomorrow');
47  $this->filenameFormat = '{filename}-{date}';
48  $this->dateFormat = 'Y-m-d';
49 
50  parent::__construct($this->getTimedFilename(), $level, $bubble, $filePermission, $useLocking);
51  }
+ Here is the call graph for this function:

Member Function Documentation

◆ close()

Monolog\Handler\RotatingFileHandler::close ( )

{}

Definition at line 56 of file RotatingFileHandler.php.

References Monolog\Handler\RotatingFileHandler\rotate().

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

57  {
58  parent::close();
59 
60  if (true === $this->mustRotate) {
61  $this->rotate();
62  }
63  }
+ 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 139 of file RotatingFileHandler.php.

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

140  {
141  $fileInfo = pathinfo($this->filename);
142  $glob = str_replace(
143  array('{filename}', '{date}'),
144  array($fileInfo['filename'], '*'),
145  $fileInfo['dirname'] . '/' . $this->filenameFormat
146  );
147  if (!empty($fileInfo['extension'])) {
148  $glob .= '.'.$fileInfo['extension'];
149  }
150 
151  return $glob;
152  }
+ Here is the caller graph for this function:

◆ getTimedFilename()

Monolog\Handler\RotatingFileHandler::getTimedFilename ( )
protected

Definition at line 123 of file RotatingFileHandler.php.

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

124  {
125  $fileInfo = pathinfo($this->filename);
126  $timedFilename = str_replace(
127  array('{filename}', '{date}'),
128  array($fileInfo['filename'], date($this->dateFormat)),
129  $fileInfo['dirname'] . '/' . $this->filenameFormat
130  );
131 
132  if (!empty($fileInfo['extension'])) {
133  $timedFilename .= '.'.$fileInfo['extension'];
134  }
135 
136  return $timedFilename;
137  }
+ Here is the caller graph for this function:

◆ rotate()

Monolog\Handler\RotatingFileHandler::rotate ( )
protected

Rotates the files.

Definition at line 94 of file RotatingFileHandler.php.

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

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

95  {
96  // update filename
97  $this->url = $this->getTimedFilename();
98  $this->nextRotation = new \DateTime('tomorrow');
99 
100  // skip GC of old logs if files are unlimited
101  if (0 === $this->maxFiles) {
102  return;
103  }
104 
105  $logFiles = glob($this->getGlobPattern());
106  if ($this->maxFiles >= count($logFiles)) {
107  // no files to remove
108  return;
109  }
110 
111  // Sorting the files by name to remove the older ones
112  usort($logFiles, function ($a, $b) {
113  return strcmp($b, $a);
114  });
115 
116  foreach (array_slice($logFiles, $this->maxFiles) as $file) {
117  if (is_writable($file)) {
118  unlink($file);
119  }
120  }
121  }
print $file
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFilenameFormat()

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

◆ write()

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

{}

Definition at line 76 of file RotatingFileHandler.php.

References Monolog\Handler\RotatingFileHandler\close().

77  {
78  // on the first record written, if the log is new, we should rotate (once per day)
79  if (null === $this->mustRotate) {
80  $this->mustRotate = !file_exists($this->url);
81  }
82 
83  if ($this->nextRotation < $record['datetime']) {
84  $this->mustRotate = true;
85  $this->close();
86  }
87 
88  parent::write($record);
89  }
+ 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 29 of file RotatingFileHandler.php.

◆ $nextRotation

Monolog\Handler\RotatingFileHandler::$nextRotation
protected

Definition at line 30 of file RotatingFileHandler.php.


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