From: Chuck Hagenbuch Date: Sun, 30 May 2010 19:33:51 +0000 (-0400) Subject: Add a Horde_Log_Handler for Scribe X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=7ba71d6a8021a9319633f1166a1ecad30ccd55d0;p=horde.git Add a Horde_Log_Handler for Scribe --- diff --git a/framework/Log/lib/Horde/Log/Handler/Scribe.php b/framework/Log/lib/Horde/Log/Handler/Scribe.php new file mode 100644 index 000000000..13e4050e7 --- /dev/null +++ b/framework/Log/lib/Horde/Log/Handler/Scribe.php @@ -0,0 +1,80 @@ + + * @author Chuck Hagenbuch + * @license http://opensource.org/licenses/bsd-license.php BSD + */ + +/** + * @category Horde + * @package Horde_Log + * @subpackage Handlers + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @license http://opensource.org/licenses/bsd-license.php BSD + */ +class Horde_Log_Handler_Scribe extends Horde_Log_Handler_Base +{ + /** + * Scribe client + * @var Horde_Scribe_Client + */ + protected $_scribe; + + /** + * Formats the log message before writing. + * @var Horde_Log_Formatter_Interface + */ + protected $_formatter; + + /** + * Options to be set by setOption(). + * @var array + */ + protected $_options = array( + 'category' => 'default', + 'addNewline' => false, + ); + + /** + * Class Constructor + * + * @param Horde_Scribe_Client $scribe Scribe client + * @param Horde_Log_Formatter_Interface $formatter Log formatter + */ + public function __construct(Horde_Scribe_Client $scribe, + Horde_Log_Formatter_Interface $formatter = null) + { + if (is_null($formatter)) { + $formatter = new Horde_Log_Formatter_Simple(); + } + + $this->_scribe = $scribe; + $this->_formatter = $formatter; + } + + /** + * Write a message to the log. + * + * @param array $event Log event + * @return bool Always True + */ + public function write($event) + { + $category = isset($event['category']) ? $event['category'] : $this->_options['category']; + + $message = $this->_formatter->format($event); + if (!$this->_options['addNewline']) { + $message = rtrim($message); + } + + $this->_scribe->log($category, $message); + + return true; + } +} diff --git a/framework/Log/package.xml b/framework/Log/package.xml index 65609b88e..f36f68df4 100644 --- a/framework/Log/package.xml +++ b/framework/Log/package.xml @@ -56,6 +56,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + @@ -80,6 +81,12 @@ http://pear.php.net/dtd/package-2.0.xsd"> pear.horde.org + + + Scribe + pear.horde.org + + @@ -97,6 +104,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> +