50 throw new \InvalidArgumentException(
'A stream must either be a resource or a string.');
62 if ($this->url && is_resource($this->stream)) {
63 fclose($this->stream);
91 protected function write(array $record)
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().');
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);
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));
111 if ($this->useLocking) {
113 flock($this->stream, LOCK_EX);
118 if ($this->useLocking) {
119 flock($this->stream, LOCK_UN);
130 fwrite(
$stream, (
string) $record[
'formatted']);
135 $this->errorMessage = preg_replace(
'{^(fopen|mkdir)\(.*?\): }',
'', $msg);
146 if ($pos ===
false) {
150 if (
'file://' === substr(
$stream, 0, 7)) {
151 return dirname(substr(
$stream, 7));
160 if ($this->dirCreated) {
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));
174 $this->dirCreated =
true;
const DEBUG
Detailed debug information.
customErrorHandler($code, $msg)
Base Handler class providing the Handler structure.
getStream()
Return the currently active stream if it is open.
__construct($stream, $level=Logger::DEBUG, $bubble=true, $filePermission=null, $useLocking=false)
streamWrite($stream, array $record)
Write to stream.
getDirFromStream($stream)
Stores to any stream resource.
getUrl()
Return the stream URL if it was configured with a URL and not an active resource. ...