diff options
Diffstat (limited to 'libs/Zend/Log/Writer')
-rw-r--r-- | libs/Zend/Log/Writer/Abstract.php | 36 | ||||
-rw-r--r-- | libs/Zend/Log/Writer/Db.php | 42 | ||||
-rw-r--r-- | libs/Zend/Log/Writer/Firebug.php | 74 | ||||
-rw-r--r-- | libs/Zend/Log/Writer/Mail.php | 26 | ||||
-rw-r--r-- | libs/Zend/Log/Writer/Mock.php | 24 | ||||
-rw-r--r-- | libs/Zend/Log/Writer/Null.php | 25 | ||||
-rw-r--r-- | libs/Zend/Log/Writer/Stream.php | 55 | ||||
-rw-r--r-- | libs/Zend/Log/Writer/Syslog.php | 20 | ||||
-rw-r--r-- | libs/Zend/Log/Writer/ZendMonitor.php | 111 |
9 files changed, 331 insertions, 82 deletions
diff --git a/libs/Zend/Log/Writer/Abstract.php b/libs/Zend/Log/Writer/Abstract.php index 3e3be2d6cd..80b939db18 100644 --- a/libs/Zend/Log/Writer/Abstract.php +++ b/libs/Zend/Log/Writer/Abstract.php @@ -15,23 +15,23 @@ * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Abstract.php 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** Zend_Log_Filter_Priority */ -require_once 'Zend/Log/Filter/Priority.php'; +// require_once 'Zend/Log/Filter/Priority.php'; /** * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Abstract.php 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $ */ -abstract class Zend_Log_Writer_Abstract +abstract class Zend_Log_Writer_Abstract implements Zend_Log_FactoryInterface { /** * @var array of Zend_Log_Filter_Interface @@ -104,4 +104,26 @@ abstract class Zend_Log_Writer_Abstract */ abstract protected function _write($event); -}
\ No newline at end of file + /** + * Validate and optionally convert the config to array + * + * @param array|Zend_Config $config Zend_Config or Array + * @return array + * @throws Zend_Log_Exception + */ + static protected function _parseConfig($config) + { + if ($config instanceof Zend_Config) { + $config = $config->toArray(); + } + + if (!is_array($config)) { + // require_once 'Zend/Log/Exception.php'; + throw new Zend_Log_Exception( + 'Configuration must be an array or instance of Zend_Config' + ); + } + + return $config; + } +} diff --git a/libs/Zend/Log/Writer/Db.php b/libs/Zend/Log/Writer/Db.php index 2130efe28e..6f77a12cb7 100644 --- a/libs/Zend/Log/Writer/Db.php +++ b/libs/Zend/Log/Writer/Db.php @@ -15,21 +15,21 @@ * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Db.php 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Db.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** Zend_Log_Writer_Abstract */ -require_once 'Zend/Log/Writer/Abstract.php'; +// require_once 'Zend/Log/Writer/Abstract.php'; /** * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Db.php 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Db.php 20096 2010-01-06 02:05:09Z bkarwin $ */ class Zend_Log_Writer_Db extends Zend_Log_Writer_Abstract { @@ -67,11 +67,38 @@ class Zend_Log_Writer_Db extends Zend_Log_Writer_Abstract } /** + * Create a new instance of Zend_Log_Writer_Db + * + * @param array|Zend_Config $config + * @return Zend_Log_Writer_Db + * @throws Zend_Log_Exception + */ + static public function factory($config) + { + $config = self::_parseConfig($config); + $config = array_merge(array( + 'db' => null, + 'table' => null, + 'columnMap' => null, + ), $config); + + if (isset($config['columnmap'])) { + $config['columnMap'] = $config['columnmap']; + } + + return new self( + $config['db'], + $config['table'], + $config['columnMap'] + ); + } + + /** * Formatting is not possible on this writer */ public function setFormatter($formatter) { - require_once 'Zend/Log/Exception.php'; + // require_once 'Zend/Log/Exception.php'; throw new Zend_Log_Exception(get_class() . ' does not support formatting'); } @@ -94,7 +121,7 @@ class Zend_Log_Writer_Db extends Zend_Log_Writer_Abstract protected function _write($event) { if ($this->_db === null) { - require_once 'Zend/Log/Exception.php'; + // require_once 'Zend/Log/Exception.php'; throw new Zend_Log_Exception('Database adapter is null'); } @@ -109,5 +136,4 @@ class Zend_Log_Writer_Db extends Zend_Log_Writer_Abstract $this->_db->insert($this->_table, $dataToInsert); } - } diff --git a/libs/Zend/Log/Writer/Firebug.php b/libs/Zend/Log/Writer/Firebug.php index 49eeae9a2d..585f6a3dc1 100644 --- a/libs/Zend/Log/Writer/Firebug.php +++ b/libs/Zend/Log/Writer/Firebug.php @@ -15,30 +15,30 @@ * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Firebug.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Firebug.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** Zend_Log */ -require_once 'Zend/Log.php'; +// require_once 'Zend/Log.php'; /** Zend_Log_Writer_Abstract */ -require_once 'Zend/Log/Writer/Abstract.php'; +// require_once 'Zend/Log/Writer/Abstract.php'; /** Zend_Log_Formatter_Firebug */ -require_once 'Zend/Log/Formatter/Firebug.php'; +// require_once 'Zend/Log/Formatter/Firebug.php'; /** Zend_Wildfire_Plugin_FirePhp */ -require_once 'Zend/Wildfire/Plugin/FirePhp.php'; +// require_once 'Zend/Wildfire/Plugin/FirePhp.php'; /** * Writes log messages to the Firebug Console via FirePHP. - * + * * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Log_Writer_Firebug extends Zend_Log_Writer_Abstract @@ -56,35 +56,47 @@ class Zend_Log_Writer_Firebug extends Zend_Log_Writer_Abstract Zend_Log::NOTICE => Zend_Wildfire_Plugin_FirePhp::INFO, Zend_Log::INFO => Zend_Wildfire_Plugin_FirePhp::INFO, Zend_Log::DEBUG => Zend_Wildfire_Plugin_FirePhp::LOG); - + /** * The default logging style for un-mapped priorities * @var string - */ + */ protected $_defaultPriorityStyle = Zend_Wildfire_Plugin_FirePhp::LOG; - + /** * Flag indicating whether the log writer is enabled * @var boolean */ protected $_enabled = true; - + /** * Class constructor */ public function __construct() { - if (php_sapi_name()=='cli') { + if (php_sapi_name() == 'cli') { $this->setEnabled(false); } - + $this->_formatter = new Zend_Log_Formatter_Firebug(); } - + /** - * Enable or disable the log writer. + * Create a new instance of Zend_Log_Writer_Firebug * - * @param boolean $enabled Set to TRUE to enable the log writer + * @param array|Zend_Config $config + * @return Zend_Log_Writer_Firebug + * @throws Zend_Log_Exception + */ + static public function factory($config) + { + return new self(); + } + + /** + * Enable or disable the log writer. + * + * @param boolean $enabled Set to TRUE to enable the log writer * @return boolean The previous value. */ public function setEnabled($enabled) @@ -93,43 +105,43 @@ class Zend_Log_Writer_Firebug extends Zend_Log_Writer_Abstract $this->_enabled = $enabled; return $previous; } - + /** * Determine if the log writer is enabled. - * + * * @return boolean Returns TRUE if the log writer is enabled. */ public function getEnabled() { return $this->_enabled; } - + /** * Set the default display style for user-defined priorities - * + * * @param string $style The default log display style * @return string Returns previous default log display style - */ + */ public function setDefaultPriorityStyle($style) { $previous = $this->_defaultPriorityStyle; $this->_defaultPriorityStyle = $style; return $previous; } - + /** * Get the default display style for user-defined priorities - * + * * @return string Returns the default log display style - */ + */ public function getDefaultPriorityStyle() { return $this->_defaultPriorityStyle; } - + /** * Set a display style for a logging priority - * + * * @param int $priority The logging priority * @param string $style The logging display style * @return string|boolean The previous logging display style if defined or TRUE otherwise @@ -146,7 +158,7 @@ class Zend_Log_Writer_Firebug extends Zend_Log_Writer_Abstract /** * Get a display style for a logging priority - * + * * @param int $priority The logging priority * @return string|boolean The logging display style if defined or FALSE otherwise */ @@ -169,15 +181,15 @@ class Zend_Log_Writer_Firebug extends Zend_Log_Writer_Abstract if (!$this->getEnabled()) { return; } - + if (array_key_exists($event['priority'],$this->_priorityStyles)) { $type = $this->_priorityStyles[$event['priority']]; } else { $type = $this->_defaultPriorityStyle; } - + $message = $this->_formatter->format($event); - + $label = isset($event['firebugLabel'])?$event['firebugLabel']:null; Zend_Wildfire_Plugin_FirePhp::getInstance()->send($message, diff --git a/libs/Zend/Log/Writer/Mail.php b/libs/Zend/Log/Writer/Mail.php index 068bd33dc1..70f57b8616 100644 --- a/libs/Zend/Log/Writer/Mail.php +++ b/libs/Zend/Log/Writer/Mail.php @@ -15,19 +15,19 @@ * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Mail.php 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Mail.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** Zend_Log_Writer_Abstract */ -require_once 'Zend/Log/Writer/Abstract.php'; +// require_once 'Zend/Log/Writer/Abstract.php'; /** Zend_Log_Exception */ -require_once 'Zend/Log/Exception.php'; +// require_once 'Zend/Log/Exception.php'; /** Zend_Log_Formatter_Simple*/ -require_once 'Zend/Log/Formatter/Simple.php'; +// require_once 'Zend/Log/Formatter/Simple.php'; /** * Class used for writing log messages to email via Zend_Mail. @@ -39,9 +39,9 @@ require_once 'Zend/Log/Formatter/Simple.php'; * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Mail.php 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Mail.php 20096 2010-01-06 02:05:09Z bkarwin $ */ class Zend_Log_Writer_Mail extends Zend_Log_Writer_Abstract { @@ -117,6 +117,18 @@ class Zend_Log_Writer_Mail extends Zend_Log_Writer_Abstract $this->_layout = $layout; $this->_formatter = new Zend_Log_Formatter_Simple(); } + + /** + * Create a new instance of Zend_Log_Writer_Mail + * + * @param array|Zend_Config $config + * @return Zend_Log_Writer_Mail + * @throws Zend_Log_Exception + */ + static public function factory($config) + { + throw new Zend_Exception('Zend_Log_Writer_Mail does not currently implement a factory'); + } /** * Places event line into array of lines to be used as message body. diff --git a/libs/Zend/Log/Writer/Mock.php b/libs/Zend/Log/Writer/Mock.php index 2a593c0d9e..1e14a2f00e 100644 --- a/libs/Zend/Log/Writer/Mock.php +++ b/libs/Zend/Log/Writer/Mock.php @@ -15,21 +15,21 @@ * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Mock.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Mock.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** Zend_Log_Writer_Abstract */ -require_once 'Zend/Log/Writer/Abstract.php'; +// require_once 'Zend/Log/Writer/Abstract.php'; /** * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Mock.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Mock.php 20096 2010-01-06 02:05:09Z bkarwin $ */ class Zend_Log_Writer_Mock extends Zend_Log_Writer_Abstract { @@ -63,4 +63,16 @@ class Zend_Log_Writer_Mock extends Zend_Log_Writer_Abstract { $this->shutdown = true; } -}
\ No newline at end of file + + /** + * Create a new instance of Zend_Log_Writer_Mock + * + * @param array|Zend_Config $config + * @return Zend_Log_Writer_Mock + * @throws Zend_Log_Exception + */ + static public function factory($config) + { + return new self(); + } +} diff --git a/libs/Zend/Log/Writer/Null.php b/libs/Zend/Log/Writer/Null.php index de791d3a99..f281883fbb 100644 --- a/libs/Zend/Log/Writer/Null.php +++ b/libs/Zend/Log/Writer/Null.php @@ -15,21 +15,21 @@ * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Null.php 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Null.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** Zend_Log_Writer_Abstract */ -require_once 'Zend/Log/Writer/Abstract.php'; +// require_once 'Zend/Log/Writer/Abstract.php'; /** * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Null.php 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Null.php 20096 2010-01-06 02:05:09Z bkarwin $ */ class Zend_Log_Writer_Null extends Zend_Log_Writer_Abstract { @@ -42,5 +42,16 @@ class Zend_Log_Writer_Null extends Zend_Log_Writer_Abstract protected function _write($event) { } - -}
\ No newline at end of file + + /** + * Create a new instance of Zend_Log_Writer_Null + * + * @param array|Zend_Config $config + * @return Zend_Log_Writer_Null + * @throws Zend_Log_Exception + */ + static public function factory($config) + { + return new self(); + } +} diff --git a/libs/Zend/Log/Writer/Stream.php b/libs/Zend/Log/Writer/Stream.php index 99b050ad6b..b722dbb4bd 100644 --- a/libs/Zend/Log/Writer/Stream.php +++ b/libs/Zend/Log/Writer/Stream.php @@ -15,24 +15,24 @@ * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Stream.php 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Stream.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** Zend_Log_Writer_Abstract */ -require_once 'Zend/Log/Writer/Abstract.php'; +// require_once 'Zend/Log/Writer/Abstract.php'; /** Zend_Log_Formatter_Simple */ -require_once 'Zend/Log/Formatter/Simple.php'; +// require_once 'Zend/Log/Formatter/Simple.php'; /** * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Stream.php 16219 2009-06-21 19:45:39Z thomas $ + * @version $Id: Stream.php 20096 2010-01-06 02:05:09Z bkarwin $ */ class Zend_Log_Writer_Stream extends Zend_Log_Writer_Abstract { @@ -48,23 +48,32 @@ class Zend_Log_Writer_Stream extends Zend_Log_Writer_Abstract * @param streamOrUrl Stream or URL to open as a stream * @param mode Mode, only applicable if a URL is given */ - public function __construct($streamOrUrl, $mode = 'a') + public function __construct($streamOrUrl, $mode = NULL) { + // Setting the default + if ($mode === NULL) { + $mode = 'a'; + } + if (is_resource($streamOrUrl)) { if (get_resource_type($streamOrUrl) != 'stream') { - require_once 'Zend/Log/Exception.php'; + // require_once 'Zend/Log/Exception.php'; throw new Zend_Log_Exception('Resource is not a stream'); } if ($mode != 'a') { - require_once 'Zend/Log/Exception.php'; + // require_once 'Zend/Log/Exception.php'; throw new Zend_Log_Exception('Mode cannot be changed on existing streams'); } $this->_stream = $streamOrUrl; } else { + if (is_array($streamOrUrl) && isset($streamOrUrl['stream'])) { + $streamOrUrl = $streamOrUrl['stream']; + } + if (! $this->_stream = @fopen($streamOrUrl, $mode, false)) { - require_once 'Zend/Log/Exception.php'; + // require_once 'Zend/Log/Exception.php'; $msg = "\"$streamOrUrl\" cannot be opened with mode \"$mode\""; throw new Zend_Log_Exception($msg); } @@ -72,7 +81,30 @@ class Zend_Log_Writer_Stream extends Zend_Log_Writer_Abstract $this->_formatter = new Zend_Log_Formatter_Simple(); } + + /** + * Create a new instance of Zend_Log_Writer_Mock + * + * @param array|Zend_Config $config + * @return Zend_Log_Writer_Mock + * @throws Zend_Log_Exception + */ + static public function factory($config) + { + $config = self::_parseConfig($config); + $config = array_merge(array( + 'stream' => null, + 'mode' => null, + ), $config); + $streamOrUrl = isset($config['url']) ? $config['url'] : $config['stream']; + + return new self( + $streamOrUrl, + $config['mode'] + ); + } + /** * Close the stream resource. * @@ -96,9 +128,8 @@ class Zend_Log_Writer_Stream extends Zend_Log_Writer_Abstract $line = $this->_formatter->format($event); if (false === @fwrite($this->_stream, $line)) { - require_once 'Zend/Log/Exception.php'; + // require_once 'Zend/Log/Exception.php'; throw new Zend_Log_Exception("Unable to write to stream"); } } - } diff --git a/libs/Zend/Log/Writer/Syslog.php b/libs/Zend/Log/Writer/Syslog.php index 3409ae56dc..310bcf54ec 100644 --- a/libs/Zend/Log/Writer/Syslog.php +++ b/libs/Zend/Log/Writer/Syslog.php @@ -15,13 +15,13 @@ * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Syslog.php 16971 2009-07-22 18:05:45Z mikaelkael $ + * @version $Id: Syslog.php 20096 2010-01-06 02:05:09Z bkarwin $ */ /** Zend_Log_Writer_Abstract */ -require_once 'Zend/Log/Writer/Abstract.php'; +// require_once 'Zend/Log/Writer/Abstract.php'; /** * Writes log messages to syslog @@ -29,7 +29,7 @@ require_once 'Zend/Log/Writer/Abstract.php'; * @category Zend * @package Zend_Log * @subpackage Writer - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Log_Writer_Syslog extends Zend_Log_Writer_Abstract @@ -95,6 +95,18 @@ class Zend_Log_Writer_Syslog extends Zend_Log_Writer_Abstract } $this->_initializeSyslog(); } + + /** + * Create a new instance of Zend_Log_Writer_Syslog + * + * @param array|Zend_Config $config + * @return Zend_Log_Writer_Syslog + * @throws Zend_Log_Exception + */ + static public function factory($config) + { + return new self(self::_parseConfig($config)); + } /** * Initialize syslog / set application name and facility diff --git a/libs/Zend/Log/Writer/ZendMonitor.php b/libs/Zend/Log/Writer/ZendMonitor.php new file mode 100644 index 0000000000..59a648fa8b --- /dev/null +++ b/libs/Zend/Log/Writer/ZendMonitor.php @@ -0,0 +1,111 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Log + * @subpackage Writer + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ + +/** Zend_Log_Writer_Abstract */ +// require_once 'Zend/Log/Writer/Abstract.php'; + +/** + * @category Zend + * @package Zend_Log + * @subpackage Writer + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +class Zend_Log_Writer_ZendMonitor extends Zend_Log_Writer_Abstract +{ + /** + * Is Zend Monitor enabled? + * @var bool + */ + protected $_isEnabled = true; + + /** + * @throws Zend_Log_Exception if Zend Monitor extension not present + */ + public function __construct() + { + if (!function_exists('monitor_custom_event')) { + $this->_isEnabled = false; + } + } + + /** + * Create a new instance of Zend_Log_Writer_ZendMonitor + * + * @param array|Zend_Config $config + * @return Zend_Log_Writer_Syslog + * @throws Zend_Log_Exception + */ + static public function factory($config) + { + return new self(); + } + + /** + * Is logging to this writer enabled? + * + * If the Zend Monitor extension is not enabled, this log writer will + * fail silently. You can query this method to determine if the log + * writer is enabled. + * + * @return bool + */ + public function isEnabled() + { + return $this->_isEnabled; + } + + /** + * Log a message to this writer. + * + * @param array $event log data event + * @return void + */ + public function write($event) + { + if (!$this->isEnabled()) { + return; + } + + parent::write($event); + } + + /** + * Write a message to the log. + * + * @param array $event log data event + * @return void + */ + protected function _write($event) + { + $priority = $event['priority']; + $message = $event['message']; + unset($event['priority'], $event['message']); + + if (!empty($event)) { + monitor_custom_event($priority, $message, $event); + } else { + monitor_custom_event($priority, $message); + } + } +} |