From 788387bd8062588ab8dc8d8ee8e3ab757cc65118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 17 Jul 2013 17:02:19 +0300 Subject: [PATCH] add error_log handler [error_log](http://www.php.net/manual/en/function.error-log.php) handler to send output to webserver SAPI handler (directly or indirectly) --- src/Monolog/Handler/ErrorLogHandler.php | 46 +++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/Monolog/Handler/ErrorLogHandler.php diff --git a/src/Monolog/Handler/ErrorLogHandler.php b/src/Monolog/Handler/ErrorLogHandler.php new file mode 100644 index 00000000..fea6de6c --- /dev/null +++ b/src/Monolog/Handler/ErrorLogHandler.php @@ -0,0 +1,46 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Monolog\Handler; + +use Monolog\Logger; + +/** + * Stores to PHP error_log() handler. + * + * @author Elan Ruusamäe + */ +class ErrorLogHandler extends AbstractProcessingHandler +{ + protected $messageType; + + /** + * @param integer $messageType Says where the error should go. + * @param integer $level The minimum logging level at which this handler will be triggered + * @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not + */ + public function __construct($messageType = 0, $level = Logger::DEBUG, $bubble = true) + { + parent::__construct($level, $bubble); + if (!in_array($messageType, array(0, 4))) { + throw new \InvalidArgumentException('Only message types 0 and 4 are supported'); + } + $this->messageType = $messageType; + } + + /** + * {@inheritdoc} + */ + protected function write(array $record) + { + error_log((string) $record['formatted'], $this->messageType); + } +}