ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
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...
 
- 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
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

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 147 of file StreamHandler.php.

References array, and Monolog\Handler\StreamHandler\getDirFromStream().

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

148  {
149  // Do not try to create dir if it has already been tried.
150  if ($this->dirCreated) {
151  return;
152  }
153 
154  $dir = $this->getDirFromStream($this->url);
155  if (null !== $dir && !is_dir($dir)) {
156  $this->errorMessage = null;
157  set_error_handler(array($this, 'customErrorHandler'));
158  $status = mkdir($dir, 0777, true);
159  restore_error_handler();
160  if (false === $status) {
161  throw new \UnexpectedValueException(sprintf('There is no existing directory at "%s" and its not buildable: '.$this->errorMessage, $dir));
162  }
163  }
164  $this->dirCreated = true;
165  }
Create styles array
The data for the language used.
+ 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 123 of file StreamHandler.php.

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

◆ getDirFromStream()

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

Definition at line 133 of file StreamHandler.php.

References Monolog\Handler\StreamHandler\$stream.

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

134  {
135  $pos = strpos($stream, '://');
136  if ($pos === false) {
137  return dirname($stream);
138  }
139 
140  if ('file://' === substr($stream, 0, 7)) {
141  return dirname(substr($stream, 7));
142  }
143 
144  return;
145  }
+ 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  }

◆ write()

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

{}

Definition at line 91 of file StreamHandler.php.

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

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  fwrite($this->stream, (string) $record['formatted']);
117 
118  if ($this->useLocking) {
119  flock($this->stream, LOCK_UN);
120  }
121  }
Create styles array
The data for the language used.
+ 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

Monolog\Handler\StreamHandler::$stream
protected

◆ $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: