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));
59 throw new \InvalidArgumentException(
'A stream must either be a resource or a string.');
71 if (is_resource($this->stream)) {
72 fclose($this->stream);
80 protected function write(array $record)
82 if (!is_resource($this->stream)) {
84 throw new \LogicException(
'Missing stream url, the stream can not be opened. This may be caused by a premature call to close().');
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);
92 restore_error_handler();
93 if (!is_resource($this->stream)) {
95 throw new \UnexpectedValueException(sprintf(
'The stream or file "%s" could not be opened: '.$this->errorMessage, $this->url));
99 if ($this->useLocking) {
101 flock($this->stream, LOCK_EX);
104 fwrite($this->stream, (
string) $record[
'formatted']);
106 if ($this->useLocking) {
107 flock($this->stream, LOCK_UN);
113 $this->errorMessage = preg_replace(
'{^(fopen|mkdir)\(.*?\): }',
'', $msg);
124 if ($pos ===
false) {
128 if (
'file://' === substr(
$stream, 0, 7)) {
129 return dirname(substr(
$stream, 7));
const DEBUG
Detailed debug information.
customErrorHandler($code, $msg)
Base Handler class providing the Handler structure.
__construct($stream, $level=Logger::DEBUG, $bubble=true, $filePermission=null, $useLocking=false)
getDirFromStream($stream)
Stores to any stream resource.