[ZF-10089] Zend_Log
[zend/radio.git] / library / Zend / Log / Writer / ZendMonitor.php
blob082f2a4f580b75c317f386446b63250f7bef3b6d
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
15 * @category Zend
16 * @package Zend_Log
17 * @subpackage Writer
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id$
23 /** Zend_Log_Writer_Abstract */
24 require_once 'Zend/Log/Writer/Abstract.php';
26 /**
27 * @category Zend
28 * @package Zend_Log
29 * @subpackage Writer
30 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
31 * @license http://framework.zend.com/license/new-bsd New BSD License
32 * @version $Id$
34 class Zend_Log_Writer_ZendMonitor extends Zend_Log_Writer_Abstract
36 /**
37 * Is Zend Monitor enabled?
38 * @var bool
40 protected $_isEnabled = true;
42 /**
43 * @throws Zend_Log_Exception if Zend Monitor extension not present
45 public function __construct()
47 if (!function_exists('monitor_custom_event')) {
48 $this->_isEnabled = false;
52 /**
53 * Create a new instance of Zend_Log_Writer_ZendMonitor
55 * @param array|Zend_Config $config
56 * @return Zend_Log_Writer_Syslog
57 * @throws Zend_Log_Exception
59 static public function factory($config)
61 return new self();
64 /**
65 * Is logging to this writer enabled?
67 * If the Zend Monitor extension is not enabled, this log writer will
68 * fail silently. You can query this method to determine if the log
69 * writer is enabled.
71 * @return bool
73 public function isEnabled()
75 return $this->_isEnabled;
78 /**
79 * Log a message to this writer.
81 * @param array $event log data event
82 * @return void
84 public function write($event)
86 if (!$this->isEnabled()) {
87 return;
90 parent::write($event);
93 /**
94 * Write a message to the log.
96 * @param array $event log data event
97 * @return void
99 protected function _write($event)
101 $priority = $event['priority'];
102 $message = $event['message'];
103 unset($event['priority'], $event['message']);
105 if (!empty($event)) {
106 monitor_custom_event($priority, $message, $event);
107 } else {
108 monitor_custom_event($priority, $message);