1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-10 07:06:40 +02:00

eAccelerator doesn't like anonymous functions.

- Change to private instance method for error handler.
This commit is contained in:
Birkir A. Barkarson
2013-10-10 14:00:41 +09:00
parent b5fa119527
commit d25b4f982a

View File

@@ -60,17 +60,19 @@ class StreamHandler extends AbstractProcessingHandler
if (!$this->url) {
throw new \LogicException('Missing stream url, the stream can not be opened. This may be caused by a premature call to close().');
}
$errorMessage = null;
set_error_handler(function ($code, $msg) use (&$errorMessage) {
$errorMessage = preg_replace('{^fopen\(.*?\): }', '', $msg);
});
set_error_handler(array($this, 'customErrorHandler'));
$this->stream = fopen($this->url, 'a');
restore_error_handler();
if (!is_resource($this->stream)) {
$this->stream = null;
throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened: '.$errorMessage, $this->url));
throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened: '.$this->errorMessage, $this->url));
}
}
fwrite($this->stream, (string) $record['formatted']);
}
private $errorMessage = null;
protected function customErrorHandler($code, $msg) {
$this->errorMessage = preg_replace('{^fopen\(.*?\): }', '', $msg);
}
}