ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Monolog\Handler\StreamHandler Class Reference

Stores to any stream resource. More...

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

Public Member Functions

 __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...
 
- 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...
 

Protected Member Functions

 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

 $stream
 
 $url
 
 $filePermission
 
 $useLocking
 
- Protected Attributes inherited from Monolog\Handler\AbstractHandler
 $level = Logger::DEBUG
 
 $bubble = true
 
 $formatter
 
 $processors = array()
 

Private Member Functions

 customErrorHandler ($code, $msg)
 
 getDirFromStream ($stream)
 

Private Attributes

 $errorMessage
 

Detailed Description

Stores to any stream resource.

Can be used to store into php://stderr, remote and local files, etc.

Author
Jordi Boggiano j.bog.nosp@m.gian.nosp@m.o@sel.nosp@m.d.be

Definition at line 23 of file StreamHandler.php.

Constructor & Destructor Documentation

◆ __construct()

Monolog\Handler\StreamHandler::__construct (   $stream,
  $level = Logger::DEBUG,
  $bubble = true,
  $filePermission = null,
  $useLocking = false 
)
Parameters
resource | string$stream
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
Exceptions

Exception If a missing directory is not buildable

Exceptions

InvalidArgumentException If stream is not a resource or string

Definition at line 41 of file StreamHandler.php.

42 {
43 parent::__construct($level, $bubble);
44 if (is_resource($stream)) {
45 $this->stream = $stream;
46 } elseif (is_string($stream)) {
47 $dir = $this->getDirFromStream($stream);
48 if (null !== $dir && !is_dir($dir)) {
49 $this->errorMessage = null;
50 set_error_handler(array($this, 'customErrorHandler'));
51 $status = mkdir($dir, 0777, true);
52 restore_error_handler();
53 if (false === $status) {
54 throw new \UnexpectedValueException(sprintf('There is no existing directory at "%s" and its not buildable: '.$this->errorMessage, $dir));
55 }
56 }
57 $this->url = $stream;
58 } else {
59 throw new \InvalidArgumentException('A stream must either be a resource or a string.');
60 }
61
62 $this->filePermission = $filePermission;
63 $this->useLocking = $useLocking;
64 }

References Monolog\Handler\AbstractHandler\$bubble, Monolog\Handler\StreamHandler\$filePermission, Monolog\Handler\AbstractHandler\$level, Monolog\Handler\StreamHandler\$stream, Monolog\Handler\StreamHandler\$useLocking, and Monolog\Handler\StreamHandler\getDirFromStream().

+ Here is the call graph for this function:

Member Function Documentation

◆ close()

Monolog\Handler\StreamHandler::close ( )

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

Reimplemented from Monolog\Handler\AbstractHandler.

Reimplemented in Monolog\Handler\RotatingFileHandler.

Definition at line 69 of file StreamHandler.php.

70 {
71 if (is_resource($this->stream)) {
72 fclose($this->stream);
73 }
74 $this->stream = null;
75 }

◆ customErrorHandler()

Monolog\Handler\StreamHandler::customErrorHandler (   $code,
  $msg 
)
private

Definition at line 111 of file StreamHandler.php.

112 {
113 $this->errorMessage = preg_replace('{^(fopen|mkdir)\‍(.*?\‍): }', '', $msg);
114 }

◆ getDirFromStream()

Monolog\Handler\StreamHandler::getDirFromStream (   $stream)
private
Parameters
string$stream
Returns
null|string

Definition at line 121 of file StreamHandler.php.

122 {
123 $pos = strpos($stream, '://');
124 if ($pos === false) {
125 return dirname($stream);
126 }
127
128 if ('file://' === substr($stream, 0, 7)) {
129 return dirname(substr($stream, 7));
130 }
131
132 return;
133 }

References Monolog\Handler\StreamHandler\$stream.

Referenced by Monolog\Handler\StreamHandler\__construct().

+ Here is the caller graph for this function:

◆ write()

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

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

Parameters
array$record
Returns
void
}

Reimplemented from Monolog\Handler\AbstractProcessingHandler.

Reimplemented in Monolog\Handler\RotatingFileHandler.

Definition at line 80 of file StreamHandler.php.

81 {
82 if (!is_resource($this->stream)) {
83 if (!$this->url) {
84 throw new \LogicException('Missing stream url, the stream can not be opened. This may be caused by a premature call to close().');
85 }
86 $this->errorMessage = null;
87 set_error_handler(array($this, 'customErrorHandler'));
88 $this->stream = fopen($this->url, 'a');
89 if ($this->filePermission !== null) {
90 @chmod($this->url, $this->filePermission);
91 }
92 restore_error_handler();
93 if (!is_resource($this->stream)) {
94 $this->stream = null;
95 throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened: '.$this->errorMessage, $this->url));
96 }
97 }
98
99 if ($this->useLocking) {
100 // ignoring errors here, there's not much we can do about them
101 flock($this->stream, LOCK_EX);
102 }
103
104 fwrite($this->stream, (string) $record['formatted']);
105
106 if ($this->useLocking) {
107 flock($this->stream, LOCK_UN);
108 }
109 }

Field Documentation

◆ $errorMessage

Monolog\Handler\StreamHandler::$errorMessage
private

Definition at line 27 of file StreamHandler.php.

◆ $filePermission

Monolog\Handler\StreamHandler::$filePermission
protected

◆ $stream

Monolog\Handler\StreamHandler::$stream
protected

◆ $url

Monolog\Handler\StreamHandler::$url
protected

Definition at line 26 of file StreamHandler.php.

◆ $useLocking

Monolog\Handler\StreamHandler::$useLocking
protected

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