CC-2166: Packaging Improvements. Moved the Zend app into airtime_mvc. It is now installed to /var/www/airtime. Storage is now set to /srv/airtime/stor. Utils are now installed to /usr/lib/airtime/utils/. Added install/airtime-dircheck.php as a simple test to see if everything is install/uninstalled correctly.

This commit is contained in:
Paul Baranowski 2011-04-14 18:55:04 -04:00
parent 514777e8d2
commit b11cbd8159
4546 changed files with 138 additions and 51 deletions

View file

@ -0,0 +1,33 @@
<?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
* @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: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Zend_Exception */
require_once 'Zend/Exception.php';
/**
* @category Zend
* @package Zend_Log
* @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: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Log_Exception extends Zend_Exception
{}

View file

@ -0,0 +1,38 @@
<?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
* @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$
*/
/**
* @category Zend
* @package Zend_Log
* @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$
*/
interface Zend_Log_FactoryInterface
{
/**
* Construct a Zend_Log driver
*
* @param array|Zen_Config $config
* @return Zend_Log_FactoryInterface
*/
static public function factory($config);
}

View file

@ -0,0 +1,60 @@
<?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$
*/
/** @see Zend_Log_Filter_Interface */
require_once 'Zend/Log/Filter/Interface.php';
/** @see Zend_Log_FactoryInterface */
require_once 'Zend/Log/FactoryInterface.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$
*/
abstract class Zend_Log_Filter_Abstract
implements Zend_Log_Filter_Interface, Zend_Log_FactoryInterface
{
/**
* 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;
}
}

View file

@ -0,0 +1,40 @@
<?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 Filter
* @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: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @category Zend
* @package Zend_Log
* @subpackage Filter
* @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: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
interface Zend_Log_Filter_Interface
{
/**
* Returns TRUE to accept the message, FALSE to block it.
*
* @param array $event event data
* @return boolean accepted?
*/
public function accept($event);
}

View file

@ -0,0 +1,85 @@
<?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 Filter
* @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: Message.php 20982 2010-02-08 15:51:36Z matthew $
*/
/** Zend_Log_Filter_Abstract */
require_once 'Zend/Log/Filter/Abstract.php';
/**
* @category Zend
* @package Zend_Log
* @subpackage Filter
* @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: Message.php 20982 2010-02-08 15:51:36Z matthew $
*/
class Zend_Log_Filter_Message extends Zend_Log_Filter_Abstract
{
/**
* @var string
*/
protected $_regexp;
/**
* Filter out any log messages not matching $regexp.
*
* @param string $regexp Regular expression to test the log message
* @throws Zend_Log_Exception
*/
public function __construct($regexp)
{
if (@preg_match($regexp, '') === false) {
require_once 'Zend/Log/Exception.php';
throw new Zend_Log_Exception("Invalid regular expression '$regexp'");
}
$this->_regexp = $regexp;
}
/**
* Create a new instance of Zend_Log_Filter_Message
*
* @param array|Zend_Config $config
* @return Zend_Log_Filter_Message
* @throws Zend_Log_Exception
*/
static public function factory($config)
{
$config = self::_parseConfig($config);
$config = array_merge(array(
'regexp' => null
), $config);
return new self(
$config['regexp']
);
}
/**
* Returns TRUE to accept the message, FALSE to block it.
*
* @param array $event event data
* @return boolean accepted?
*/
public function accept($event)
{
return preg_match($this->_regexp, $event['message']) > 0;
}
}

View file

@ -0,0 +1,101 @@
<?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 Filter
* @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: Priority.php 20260 2010-01-13 18:29:22Z ralph $
*/
/** Zend_Log_Filter_Abstract */
require_once 'Zend/Log/Filter/Abstract.php';
/**
* @category Zend
* @package Zend_Log
* @subpackage Filter
* @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: Priority.php 20260 2010-01-13 18:29:22Z ralph $
*/
class Zend_Log_Filter_Priority extends Zend_Log_Filter_Abstract
{
/**
* @var integer
*/
protected $_priority;
/**
* @var string
*/
protected $_operator;
/**
* Filter logging by $priority. By default, it will accept any log
* event whose priority value is less than or equal to $priority.
*
* @param integer $priority Priority
* @param string $operator Comparison operator
* @throws Zend_Log_Exception
*/
public function __construct($priority, $operator = NULL)
{
if (! is_integer($priority)) {
require_once 'Zend/Log/Exception.php';
throw new Zend_Log_Exception('Priority must be an integer');
}
$this->_priority = $priority;
$this->_operator = is_null($operator) ? '<=' : $operator;
}
/**
* Create a new instance of Zend_Log_Filter_Priority
*
* @param array|Zend_Config $config
* @return Zend_Log_Filter_Priority
* @throws Zend_Log_Exception
*/
static public function factory($config)
{
$config = self::_parseConfig($config);
$config = array_merge(array(
'priority' => null,
'operator' => null,
), $config);
// Add support for constants
if (!is_numeric($config['priority']) && isset($config['priority']) && defined($config['priority'])) {
$config['priority'] = constant($config['priority']);
}
return new self(
(int) $config['priority'],
$config['operator']
);
}
/**
* Returns TRUE to accept the message, FALSE to block it.
*
* @param array $event event data
* @return boolean accepted?
*/
public function accept($event)
{
return version_compare($event['priority'], $this->_priority, $this->_operator);
}
}

View file

@ -0,0 +1,77 @@
<?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 Filter
* @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: Suppress.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Zend_Log_Filter_Interface */
require_once 'Zend/Log/Filter/Interface.php';
/**
* @category Zend
* @package Zend_Log
* @subpackage Filter
* @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: Suppress.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Log_Filter_Suppress extends Zend_Log_Filter_Abstract
{
/**
* @var boolean
*/
protected $_accept = true;
/**
* This is a simple boolean filter.
*
* Call suppress(true) to suppress all log events.
* Call suppress(false) to accept all log events.
*
* @param boolean $suppress Should all log events be suppressed?
* @return void
*/
public function suppress($suppress)
{
$this->_accept = (! $suppress);
}
/**
* Returns TRUE to accept the message, FALSE to block it.
*
* @param array $event event data
* @return boolean accepted?
*/
public function accept($event)
{
return $this->_accept;
}
/**
* Create a new instance of Zend_Log_Filter_Suppress
*
* @param array|Zend_Config $config
* @return Zend_Log_Filter_Suppress
* @throws Zend_Log_Exception
*/
static public function factory($config)
{
return new self();
}
}

View file

@ -0,0 +1,50 @@
<?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 Formatter
* @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 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Zend_Log_Formatter_Interface */
require_once 'Zend/Log/Formatter/Interface.php';
/**
* @category Zend
* @package Zend_Log
* @subpackage Formatter
* @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_Formatter_Firebug implements Zend_Log_Formatter_Interface
{
/**
* This method formats the event for the firebug writer.
*
* The default is to just send the message parameter, but through
* extension of this class and calling the
* {@see Zend_Log_Writer_Firebug::setFormatter()} method you can
* pass as much of the event data as you are interested in.
*
* @param array $event event data
* @return mixed event message
*/
public function format($event)
{
return $event['message'];
}
}

View file

@ -0,0 +1,41 @@
<?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 Formatter
* @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: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @category Zend
* @package Zend_Log
* @subpackage Formatter
* @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: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
interface Zend_Log_Formatter_Interface
{
/**
* Formats data into a single line to be written by the writer.
*
* @param array $event event data
* @return string formatted line to write to the log
*/
public function format($event);
}

View file

@ -0,0 +1,85 @@
<?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 Formatter
* @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: Simple.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Zend_Log_Formatter_Interface */
require_once 'Zend/Log/Formatter/Interface.php';
/**
* @category Zend
* @package Zend_Log
* @subpackage Formatter
* @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: Simple.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Log_Formatter_Simple implements Zend_Log_Formatter_Interface
{
/**
* @var string
*/
protected $_format;
const DEFAULT_FORMAT = '%timestamp% %priorityName% (%priority%): %message%';
/**
* Class constructor
*
* @param null|string $format Format specifier for log messages
* @throws Zend_Log_Exception
*/
public function __construct($format = null)
{
if ($format === null) {
$format = self::DEFAULT_FORMAT . PHP_EOL;
}
if (! is_string($format)) {
require_once 'Zend/Log/Exception.php';
throw new Zend_Log_Exception('Format must be a string');
}
$this->_format = $format;
}
/**
* Formats data into a single line to be written by the writer.
*
* @param array $event event data
* @return string formatted line to write to the log
*/
public function format($event)
{
$output = $this->_format;
foreach ($event as $name => $value) {
if ((is_object($value) && !method_exists($value,'__toString'))
|| is_array($value)) {
$value = gettype($value);
}
$output = str_replace("%$name%", $value, $output);
}
return $output;
}
}

View file

@ -0,0 +1,121 @@
<?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 Formatter
* @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: Xml.php 20104 2010-01-06 21:26:01Z matthew $
*/
/** Zend_Log_Formatter_Interface */
require_once 'Zend/Log/Formatter/Interface.php';
/**
* @category Zend
* @package Zend_Log
* @subpackage Formatter
* @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: Xml.php 20104 2010-01-06 21:26:01Z matthew $
*/
class Zend_Log_Formatter_Xml implements Zend_Log_Formatter_Interface
{
/**
* @var Relates XML elements to log data field keys.
*/
protected $_rootElement;
/**
* @var Relates XML elements to log data field keys.
*/
protected $_elementMap;
/**
* @var string Encoding to use in XML
*/
protected $_encoding;
/**
* Class constructor
*
* @param string $rootElement Name of root element
* @param array $elementMap
* @param string $encoding Encoding to use (defaults to UTF-8)
*/
public function __construct($rootElement = 'logEntry', $elementMap = null, $encoding = 'UTF-8')
{
$this->_rootElement = $rootElement;
$this->_elementMap = $elementMap;
$this->setEncoding($encoding);
}
/**
* Get encoding
*
* @return string
*/
public function getEncoding()
{
return $this->_encoding;
}
/**
* Set encoding
*
* @param string $value
* @return Zend_Log_Formatter_Xml
*/
public function setEncoding($value)
{
$this->_encoding = (string) $value;
return $this;
}
/**
* Formats data into a single line to be written by the writer.
*
* @param array $event event data
* @return string formatted line to write to the log
*/
public function format($event)
{
if ($this->_elementMap === null) {
$dataToInsert = $event;
} else {
$dataToInsert = array();
foreach ($this->_elementMap as $elementName => $fieldKey) {
$dataToInsert[$elementName] = $event[$fieldKey];
}
}
$enc = $this->getEncoding();
$dom = new DOMDocument('1.0', $enc);
$elt = $dom->appendChild(new DOMElement($this->_rootElement));
foreach ($dataToInsert as $key => $value) {
if($key == "message") {
$value = htmlspecialchars($value, ENT_COMPAT, $enc);
}
$elt->appendChild(new DOMElement($key, $value));
}
$xml = $dom->saveXML();
$xml = preg_replace('/<\?xml version="1.0"( encoding="[^\"]*")?\?>\n/u', '', $xml);
return $xml . PHP_EOL;
}
}

View file

@ -0,0 +1,129 @@
<?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: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Zend_Log_Filter_Priority */
require_once 'Zend/Log/Filter/Priority.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: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
abstract class Zend_Log_Writer_Abstract implements Zend_Log_FactoryInterface
{
/**
* @var array of Zend_Log_Filter_Interface
*/
protected $_filters = array();
/**
* Formats the log message before writing.
* @var Zend_Log_Formatter_Interface
*/
protected $_formatter;
/**
* Add a filter specific to this writer.
*
* @param Zend_Log_Filter_Interface $filter
* @return void
*/
public function addFilter($filter)
{
if (is_integer($filter)) {
$filter = new Zend_Log_Filter_Priority($filter);
}
$this->_filters[] = $filter;
}
/**
* Log a message to this writer.
*
* @param array $event log data event
* @return void
*/
public function write($event)
{
foreach ($this->_filters as $filter) {
if (! $filter->accept($event)) {
return;
}
}
// exception occurs on error
$this->_write($event);
}
/**
* Set a new formatter for this writer
*
* @param Zend_Log_Formatter_Interface $formatter
* @return void
*/
public function setFormatter($formatter)
{
$this->_formatter = $formatter;
}
/**
* Perform shutdown activites such as closing open resources
*
* @return void
*/
public function shutdown()
{}
/**
* Write a message to the log.
*
* @param array $event log data event
* @return void
*/
abstract protected function _write($event);
/**
* 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;
}
}

View file

@ -0,0 +1,139 @@
<?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: Db.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** 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: Db.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Log_Writer_Db extends Zend_Log_Writer_Abstract
{
/**
* Database adapter instance
* @var Zend_Db_Adapter
*/
private $_db;
/**
* Name of the log table in the database
* @var string
*/
private $_table;
/**
* Relates database columns names to log data field keys.
*
* @var null|array
*/
private $_columnMap;
/**
* Class constructor
*
* @param Zend_Db_Adapter $db Database adapter instance
* @param string $table Log table in database
* @param array $columnMap
*/
public function __construct($db, $table, $columnMap = null)
{
$this->_db = $db;
$this->_table = $table;
$this->_columnMap = $columnMap;
}
/**
* 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';
throw new Zend_Log_Exception(get_class() . ' does not support formatting');
}
/**
* Remove reference to database adapter
*
* @return void
*/
public function shutdown()
{
$this->_db = null;
}
/**
* Write a message to the log.
*
* @param array $event event data
* @return void
*/
protected function _write($event)
{
if ($this->_db === null) {
require_once 'Zend/Log/Exception.php';
throw new Zend_Log_Exception('Database adapter is null');
}
if ($this->_columnMap === null) {
$dataToInsert = $event;
} else {
$dataToInsert = array();
foreach ($this->_columnMap as $columnName => $fieldKey) {
$dataToInsert[$columnName] = $event[$fieldKey];
}
}
$this->_db->insert($this->_table, $dataToInsert);
}
}

View file

@ -0,0 +1,200 @@
<?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: Firebug.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Zend_Log */
require_once 'Zend/Log.php';
/** Zend_Log_Writer_Abstract */
require_once 'Zend/Log/Writer/Abstract.php';
/** Zend_Log_Formatter_Firebug */
require_once 'Zend/Log/Formatter/Firebug.php';
/** Zend_Wildfire_Plugin_FirePhp */
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-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
{
/**
* Maps logging priorities to logging display styles
* @var array
*/
protected $_priorityStyles = array(Zend_Log::EMERG => Zend_Wildfire_Plugin_FirePhp::ERROR,
Zend_Log::ALERT => Zend_Wildfire_Plugin_FirePhp::ERROR,
Zend_Log::CRIT => Zend_Wildfire_Plugin_FirePhp::ERROR,
Zend_Log::ERR => Zend_Wildfire_Plugin_FirePhp::ERROR,
Zend_Log::WARN => Zend_Wildfire_Plugin_FirePhp::WARN,
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') {
$this->setEnabled(false);
}
$this->_formatter = new Zend_Log_Formatter_Firebug();
}
/**
* Create a new instance of Zend_Log_Writer_Firebug
*
* @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)
{
$previous = $this->_enabled;
$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
*/
public function setPriorityStyle($priority, $style)
{
$previous = true;
if (array_key_exists($priority,$this->_priorityStyles)) {
$previous = $this->_priorityStyles[$priority];
}
$this->_priorityStyles[$priority] = $style;
return $previous;
}
/**
* 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
*/
public function getPriorityStyle($priority)
{
if (array_key_exists($priority,$this->_priorityStyles)) {
return $this->_priorityStyles[$priority];
}
return false;
}
/**
* Log a message to the Firebug Console.
*
* @param array $event The event data
* @return void
*/
protected function _write($event)
{
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,
$label,
$type,
array('traceOffset'=>6));
}
}

View file

@ -0,0 +1,307 @@
<?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: Mail.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Zend_Log_Writer_Abstract */
require_once 'Zend/Log/Writer/Abstract.php';
/** Zend_Log_Exception */
require_once 'Zend/Log/Exception.php';
/** Zend_Log_Formatter_Simple*/
require_once 'Zend/Log/Formatter/Simple.php';
/**
* Class used for writing log messages to email via Zend_Mail.
*
* Allows for emailing log messages at and above a certain level via a
* Zend_Mail object. Note that this class only sends the email upon
* completion, so any log entries accumulated are sent in a single email.
*
* @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: Mail.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Log_Writer_Mail extends Zend_Log_Writer_Abstract
{
/**
* Array of formatted events to include in message body.
*
* @var array
*/
protected $_eventsToMail = array();
/**
* Array of formatted lines for use in an HTML email body; these events
* are formatted with an optional formatter if the caller is using
* Zend_Layout.
*
* @var array
*/
protected $_layoutEventsToMail = array();
/**
* Zend_Mail instance to use
*
* @var Zend_Mail
*/
protected $_mail;
/**
* Zend_Layout instance to use; optional.
*
* @var Zend_Layout
*/
protected $_layout;
/**
* Optional formatter for use when rendering with Zend_Layout.
*
* @var Zend_Log_Formatter_Interface
*/
protected $_layoutFormatter;
/**
* Array keeping track of the number of entries per priority level.
*
* @var array
*/
protected $_numEntriesPerPriority = array();
/**
* Subject prepend text.
*
* Can only be used of the Zend_Mail object has not already had its
* subject line set. Using this will cause the subject to have the entry
* counts per-priority level appended to it.
*
* @var string|null
*/
protected $_subjectPrependText;
/**
* Class constructor.
*
* Constructs the mail writer; requires a Zend_Mail instance, and takes an
* optional Zend_Layout instance. If Zend_Layout is being used,
* $this->_layout->events will be set for use in the layout template.
*
* @param Zend_Mail $mail Mail instance
* @param Zend_Layout $layout Layout instance; optional
* @return void
*/
public function __construct(Zend_Mail $mail, Zend_Layout $layout = null)
{
$this->_mail = $mail;
$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.
*
* Handles the formatting of both plaintext entries, as well as those
* rendered with Zend_Layout.
*
* @param array $event Event data
* @return void
*/
protected function _write($event)
{
// Track the number of entries per priority level.
if (!isset($this->_numEntriesPerPriority[$event['priorityName']])) {
$this->_numEntriesPerPriority[$event['priorityName']] = 1;
} else {
$this->_numEntriesPerPriority[$event['priorityName']]++;
}
$formattedEvent = $this->_formatter->format($event);
// All plaintext events are to use the standard formatter.
$this->_eventsToMail[] = $formattedEvent;
// If we have a Zend_Layout instance, use a specific formatter for the
// layout if one exists. Otherwise, just use the event with its
// default format.
if ($this->_layout) {
if ($this->_layoutFormatter) {
$this->_layoutEventsToMail[] =
$this->_layoutFormatter->format($event);
} else {
$this->_layoutEventsToMail[] = $formattedEvent;
}
}
}
/**
* Gets instance of Zend_Log_Formatter_Instance used for formatting a
* message using Zend_Layout, if applicable.
*
* @return Zend_Log_Formatter_Interface|null The formatter, or null.
*/
public function getLayoutFormatter()
{
return $this->_layoutFormatter;
}
/**
* Sets a specific formatter for use with Zend_Layout events.
*
* Allows use of a second formatter on lines that will be rendered with
* Zend_Layout. In the event that Zend_Layout is not being used, this
* formatter cannot be set, so an exception will be thrown.
*
* @param Zend_Log_Formatter_Interface $formatter
* @return Zend_Log_Writer_Mail
* @throws Zend_Log_Exception
*/
public function setLayoutFormatter(Zend_Log_Formatter_Interface $formatter)
{
if (!$this->_layout) {
throw new Zend_Log_Exception(
'cannot set formatter for layout; ' .
'a Zend_Layout instance is not in use');
}
$this->_layoutFormatter = $formatter;
return $this;
}
/**
* Allows caller to have the mail subject dynamically set to contain the
* entry counts per-priority level.
*
* Sets the text for use in the subject, with entry counts per-priority
* level appended to the end. Since a Zend_Mail subject can only be set
* once, this method cannot be used if the Zend_Mail object already has a
* subject set.
*
* @param string $subject Subject prepend text.
* @return Zend_Log_Writer_Mail
*/
public function setSubjectPrependText($subject)
{
if ($this->_mail->getSubject()) {
throw new Zend_Log_Exception(
'subject already set on mail; ' .
'cannot set subject prepend text');
}
$this->_subjectPrependText = (string) $subject;
return $this;
}
/**
* Sends mail to recipient(s) if log entries are present. Note that both
* plaintext and HTML portions of email are handled here.
*
* @return void
*/
public function shutdown()
{
// If there are events to mail, use them as message body. Otherwise,
// there is no mail to be sent.
if (empty($this->_eventsToMail)) {
return;
}
if ($this->_subjectPrependText !== null) {
// Tack on the summary of entries per-priority to the subject
// line and set it on the Zend_Mail object.
$numEntries = $this->_getFormattedNumEntriesPerPriority();
$this->_mail->setSubject(
"{$this->_subjectPrependText} ({$numEntries})");
}
// Always provide events to mail as plaintext.
$this->_mail->setBodyText(implode('', $this->_eventsToMail));
// If a Zend_Layout instance is being used, set its "events"
// value to the lines formatted for use with the layout.
if ($this->_layout) {
// Set the required "messages" value for the layout. Here we
// are assuming that the layout is for use with HTML.
$this->_layout->events =
implode('', $this->_layoutEventsToMail);
// If an exception occurs during rendering, convert it to a notice
// so we can avoid an exception thrown without a stack frame.
try {
$this->_mail->setBodyHtml($this->_layout->render());
} catch (Exception $e) {
trigger_error(
"exception occurred when rendering layout; " .
"unable to set html body for message; " .
"message = {$e->getMessage()}; " .
"code = {$e->getCode()}; " .
"exception class = " . get_class($e),
E_USER_NOTICE);
}
}
// Finally, send the mail. If an exception occurs, convert it into a
// warning-level message so we can avoid an exception thrown without a
// stack frame.
try {
$this->_mail->send();
} catch (Exception $e) {
trigger_error(
"unable to send log entries via email; " .
"message = {$e->getMessage()}; " .
"code = {$e->getCode()}; " .
"exception class = " . get_class($e),
E_USER_WARNING);
}
}
/**
* Gets a string of number of entries per-priority level that occurred, or
* an emptry string if none occurred.
*
* @return string
*/
protected function _getFormattedNumEntriesPerPriority()
{
$strings = array();
foreach ($this->_numEntriesPerPriority as $priority => $numEntries) {
$strings[] = "{$priority}={$numEntries}";
}
return implode(', ', $strings);
}
}

View file

@ -0,0 +1,78 @@
<?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: Mock.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** 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: Mock.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Log_Writer_Mock extends Zend_Log_Writer_Abstract
{
/**
* array of log events
*/
public $events = array();
/**
* shutdown called?
*/
public $shutdown = false;
/**
* Write a message to the log.
*
* @param array $event event data
* @return void
*/
public function _write($event)
{
$this->events[] = $event;
}
/**
* Record shutdown
*
* @return void
*/
public function shutdown()
{
$this->shutdown = true;
}
/**
* 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();
}
}

View file

@ -0,0 +1,57 @@
<?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: Null.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** 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: Null.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Log_Writer_Null extends Zend_Log_Writer_Abstract
{
/**
* Write a message to the log.
*
* @param array $event event data
* @return void
*/
protected function _write($event)
{
}
/**
* 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();
}
}

View file

@ -0,0 +1,135 @@
<?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: Stream.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Zend_Log_Writer_Abstract */
require_once 'Zend/Log/Writer/Abstract.php';
/** Zend_Log_Formatter_Simple */
require_once 'Zend/Log/Formatter/Simple.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: Stream.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
class Zend_Log_Writer_Stream extends Zend_Log_Writer_Abstract
{
/**
* Holds the PHP stream to log to.
* @var null|stream
*/
protected $_stream = null;
/**
* Class Constructor
*
* @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 = 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';
throw new Zend_Log_Exception('Resource is not a stream');
}
if ($mode != 'a') {
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';
$msg = "\"$streamOrUrl\" cannot be opened with mode \"$mode\"";
throw new Zend_Log_Exception($msg);
}
}
$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.
*
* @return void
*/
public function shutdown()
{
if (is_resource($this->_stream)) {
fclose($this->_stream);
}
}
/**
* Write a message to the log.
*
* @param array $event event data
* @return void
*/
protected function _write($event)
{
$line = $this->_formatter->format($event);
if (false === @fwrite($this->_stream, $line)) {
require_once 'Zend/Log/Exception.php';
throw new Zend_Log_Exception("Unable to write to stream");
}
}
}

View file

@ -0,0 +1,187 @@
<?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: Syslog.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/** Zend_Log_Writer_Abstract */
require_once 'Zend/Log/Writer/Abstract.php';
/**
* Writes log messages to syslog
*
* @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
*/
class Zend_Log_Writer_Syslog extends Zend_Log_Writer_Abstract
{
/**
* Maps Zend_Log priorities to PHP's syslog priorities
* @var array
*/
protected $_priorities = array(
Zend_Log::EMERG => LOG_EMERG,
Zend_Log::ALERT => LOG_ALERT,
Zend_Log::CRIT => LOG_CRIT,
Zend_Log::ERR => LOG_ERR,
Zend_Log::WARN => LOG_WARNING,
Zend_Log::NOTICE => LOG_NOTICE,
Zend_Log::INFO => LOG_INFO,
Zend_Log::DEBUG => LOG_DEBUG,
);
/**
* The default log priority - for unmapped custom priorities
* @var string
*/
protected $_defaultPriority = LOG_NOTICE;
/**
* Last application name set by a syslog-writer instance
* @var string
*/
protected static $_lastApplication;
/**
* Last facility name set by a syslog-writer instance
* @var string
*/
protected static $_lastFacility;
/**
* Application name used by this syslog-writer instance
* @var string
*/
protected $_application = 'Zend_Log';
/**
* Facility used by this syslog-writer instance
* @var string
*/
protected $_facility = LOG_USER;
/**
* Class constructor
*
* @param array $options Array of options; may include "application" and "facility" keys
* @return void
*/
public function __construct(array $params = array())
{
if (isset($params['application'])) {
$this->_application = $params['application'];
}
if (isset($params['facility'])) {
$this->_facility = $params['facility'];
}
$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
*
* @param string $application Application name
* @param string $facility Syslog facility
* @return void
*/
protected function _initializeSyslog()
{
self::$_lastApplication = $this->_application;
self::$_lastFacility = $this->_facility;
openlog($this->_application, LOG_PID, $this->_facility);
}
/**
* Set syslog facility
*
* @param string $facility Syslog facility
* @return void
*/
public function setFacility($facility)
{
if ($this->_facility === $facility) {
return;
}
$this->_facility = $facility;
$this->_initializeSyslog();
}
/**
* Set application name
*
* @param string $application Application name
* @return void
*/
public function setApplicationName($application)
{
if ($this->_application === $application) {
return;
}
$this->_application = $application;
$this->_initializeSyslog();
}
/**
* Close syslog.
*
* @return void
*/
public function shutdown()
{
closelog();
}
/**
* Write a message to syslog.
*
* @param array $event event data
* @return void
*/
protected function _write($event)
{
if (array_key_exists($event['priority'], $this->_priorities)) {
$priority = $this->_priorities[$event['priority']];
} else {
$priority = $this->_defaultPriority;
}
if ($this->_application !== self::$_lastApplication
|| $this->_facility !== self::$_lastFacility)
{
$this->_initializeSyslog();
}
syslog($priority, $event['message']);
}
}

View file

@ -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);
}
}
}