ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 ()
 {} 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
bool 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
bool
} 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 ()
 
 reset ()
 

Protected Member Functions

 write (array $record)
 {} More...
 
 streamWrite ($stream, array $record)
 Write to stream. 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)
 
 createDir ()
 

Private Attributes

 $errorMessage
 
 $dirCreated
 

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
int$levelThe minimum logging level at which this handler will be triggered
bool$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)
bool$useLockingTry to lock log file before doing any writes
Exceptions

Definition at line 42 of file StreamHandler.php.

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

43  {
44  parent::__construct($level, $bubble);
45  if (is_resource($stream)) {
46  $this->stream = $stream;
47  } elseif (is_string($stream)) {
48  $this->url = $stream;
49  } else {
50  throw new \InvalidArgumentException('A stream must either be a resource or a string.');
51  }
52 
53  $this->filePermission = $filePermission;
54  $this->useLocking = $useLocking;
55  }

Member Function Documentation

◆ close()

Monolog\Handler\StreamHandler::close ( )

{}

Definition at line 60 of file StreamHandler.php.

61  {
62  if ($this->url && is_resource($this->stream)) {
63  fclose($this->stream);
64  }
65  $this->stream = null;
66  }

◆ createDir()

Monolog\Handler\StreamHandler::createDir ( )
private

Definition at line 157 of file StreamHandler.php.

References Monolog\Handler\StreamHandler\getDirFromStream().

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

158  {
159  // Do not try to create dir if it has already been tried.
160  if ($this->dirCreated) {
161  return;
162  }
163 
164  $dir = $this->getDirFromStream($this->url);
165  if (null !== $dir && !is_dir($dir)) {
166  $this->errorMessage = null;
167  set_error_handler(array($this, 'customErrorHandler'));
168  $status = mkdir($dir, 0777, true);
169  restore_error_handler();
170  if (false === $status && !is_dir($dir)) {
171  throw new \UnexpectedValueException(sprintf('There is no existing directory at "%s" and its not buildable: '.$this->errorMessage, $dir));
172  }
173  }
174  $this->dirCreated = true;
175  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ customErrorHandler()

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

Definition at line 133 of file StreamHandler.php.

134  {
135  $this->errorMessage = preg_replace('{^(fopen|mkdir)\(.*?\): }', '', $msg);
136  }

◆ getDirFromStream()

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

Definition at line 143 of file StreamHandler.php.

References Monolog\Handler\StreamHandler\$stream.

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

144  {
145  $pos = strpos($stream, '://');
146  if ($pos === false) {
147  return dirname($stream);
148  }
149 
150  if ('file://' === substr($stream, 0, 7)) {
151  return dirname(substr($stream, 7));
152  }
153 
154  return;
155  }
+ Here is the caller graph for this function:

◆ getStream()

Monolog\Handler\StreamHandler::getStream ( )

Return the currently active stream if it is open.

Returns
resource|null

Definition at line 73 of file StreamHandler.php.

References Monolog\Handler\StreamHandler\$stream.

74  {
75  return $this->stream;
76  }

◆ getUrl()

Monolog\Handler\StreamHandler::getUrl ( )

Return the stream URL if it was configured with a URL and not an active resource.

Returns
string|null

Definition at line 83 of file StreamHandler.php.

References Monolog\Handler\StreamHandler\$url.

84  {
85  return $this->url;
86  }

◆ streamWrite()

Monolog\Handler\StreamHandler::streamWrite (   $stream,
array  $record 
)
protected

Write to stream.

Parameters
resource$stream
array$record

Definition at line 128 of file StreamHandler.php.

References Monolog\Handler\StreamHandler\$stream.

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

129  {
130  fwrite($stream, (string) $record['formatted']);
131  }
+ Here is the caller graph for this function:

◆ write()

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

{}

Definition at line 91 of file StreamHandler.php.

References Monolog\Handler\StreamHandler\createDir(), and Monolog\Handler\StreamHandler\streamWrite().

92  {
93  if (!is_resource($this->stream)) {
94  if (null === $this->url || '' === $this->url) {
95  throw new \LogicException('Missing stream url, the stream can not be opened. This may be caused by a premature call to close().');
96  }
97  $this->createDir();
98  $this->errorMessage = null;
99  set_error_handler(array($this, 'customErrorHandler'));
100  $this->stream = fopen($this->url, 'a');
101  if ($this->filePermission !== null) {
102  @chmod($this->url, $this->filePermission);
103  }
104  restore_error_handler();
105  if (!is_resource($this->stream)) {
106  $this->stream = null;
107  throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened: '.$this->errorMessage, $this->url));
108  }
109  }
110 
111  if ($this->useLocking) {
112  // ignoring errors here, there's not much we can do about them
113  flock($this->stream, LOCK_EX);
114  }
115 
116  $this->streamWrite($this->stream, $record);
117 
118  if ($this->useLocking) {
119  flock($this->stream, LOCK_UN);
120  }
121  }
streamWrite($stream, array $record)
Write to stream.
+ Here is the call graph for this function:

Field Documentation

◆ $dirCreated

Monolog\Handler\StreamHandler::$dirCreated
private

Definition at line 30 of file StreamHandler.php.

◆ $errorMessage

Monolog\Handler\StreamHandler::$errorMessage
private

Definition at line 27 of file StreamHandler.php.

◆ $filePermission

Monolog\Handler\StreamHandler::$filePermission
protected

◆ $stream

◆ $url

Monolog\Handler\StreamHandler::$url
protected

Definition at line 26 of file StreamHandler.php.

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

◆ $useLocking

Monolog\Handler\StreamHandler::$useLocking
protected

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