Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of git://git.zendframework.com/zf
Browse files Browse the repository at this point in the history
  • Loading branch information
Shahar Evron committed Jul 25, 2010
5 parents 307038c + dea5efb + 7e2c3cc + ce0f62a + 2d857f5 commit 827c6af
Show file tree
Hide file tree
Showing 14 changed files with 556 additions and 47 deletions.
3 changes: 1 addition & 2 deletions src/Filter/AbstractFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
abstract class AbstractFilter
implements Filter, Factory
abstract class AbstractFilter implements Filter, Factory
{
/**
* Validate and optionally convert the config to array
Expand Down
46 changes: 42 additions & 4 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,25 @@ class Logger implements Factory
* @var callback
*/
protected $_origErrorHandler = null;

/**
*
* @var boolean
*/
protected $_registeredErrorHandler = false;

/**
*
* @var array
*/
protected $_errorHandlerMap = false;

/**
*
* @var string
*/
protected $_timestampFormat = 'c';

/**
* Class constructor. Create a new logger
*
Expand Down Expand Up @@ -154,6 +160,9 @@ protected function _constructWriterFromConfig($config)
$writer = $this->_constructFromConfig('writer', $config, $this->_defaultWriterNamespace);

if (!$writer instanceof Writer) {
$writerName = is_object($writer)
? get_class($writer)
: 'The specified writer';
throw new Exception("{$writerName} does not extend Zend\\Log\\Writer!");
}

Expand All @@ -176,6 +185,9 @@ protected function _constructFilterFromConfig($config)
$filter = $this->_constructFromConfig('filter', $config, $this->_defaultFilterNamespace);

if (!$filter instanceof Filter) {
$filterName = is_object($filter)
? get_class($filter)
: 'The specified filter';
throw new Exception("{$filterName} does not implement Zend\\Log\\Filter");
}

Expand Down Expand Up @@ -252,7 +264,7 @@ protected function getClassName($config, $type, $defaultNamespace)
protected function _packEvent($message, $priority)
{
return array_merge(array(
'timestamp' => date('c'),
'timestamp' => date($this->_timestampFormat),
'message' => $message,
'priority' => $priority,
'priorityName' => $this->_priorities[$priority]
Expand Down Expand Up @@ -374,11 +386,12 @@ public function addPriority($name, $priority)
$name = strtoupper($name);

if (isset($this->_priorities[$priority])
|| array_search($name, $this->_priorities)) {
|| false !== array_search($name, $this->_priorities)) {
throw new Exception('Existing priorities cannot be overwritten');
}

$this->_priorities[$priority] = $name;
return $this;
}

/**
Expand All @@ -402,6 +415,7 @@ public function addFilter($filter)
}

$this->_filters[] = $filter;
return $this;
}

/**
Expand All @@ -425,6 +439,7 @@ public function addWriter($writer)
}

$this->_writers[] = $writer;
return $this;
}

/**
Expand All @@ -437,6 +452,7 @@ public function addWriter($writer)
public function setEventItem($name, $value)
{
$this->_extras = array_merge($this->_extras, array($name => $value));
return $this;
}

/**
Expand Down Expand Up @@ -513,4 +529,26 @@ public function errorHandler($errno, $errstr, $errfile, $errline, $errcontext)
}
return false;
}

/**
* Set timestamp format for log entries.
*
* @param string $format
* @return Zend\Log\Logger
*/
public function setTimestampFormat($format)
{
$this->_timestampFormat = $format;
return $this;
}

/**
* Get timestamp format used for log entries.
*
* @return string
*/
public function getTimestampFormat()
{
return $this->_timestampFormat;
}
}
6 changes: 6 additions & 0 deletions src/Writer/AbstractWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ public function addFilter($filter)
$filter = new \Zend\Log\Filter\Priority($filter);
}

if (!$filter instanceof \Zend\Log\Filter) {
throw new \Zend\Log\Exception('Invalid filter provided');
}

$this->_filters[] = $filter;
return $this;
}

/**
Expand Down Expand Up @@ -94,6 +99,7 @@ public function write($event)
public function setFormatter($formatter)
{
$this->_formatter = $formatter;
return $this;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/Writer/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ static public function factory($config = array())
{
$config = self::_parseConfig($config);
$config = array_merge(array(
'db' => null,
'table' => null,
'db' => null,
'table' => null,
'columnMap' => null,
), $config);

if (isset($config['columnmap'])) {
$config['columnMap'] = $config['columnmap'];
}

return new self(
$config['db'],
$config['table'],
Expand All @@ -101,7 +101,7 @@ static public function factory($config = array())
/**
* Formatting is not possible on this writer
*/
public function setFormatter($formatter)
public function setFormatter(Zend_Log_Formatter_Interface $formatter)
{
throw new Log\Exception(get_class() . ' does not support formatting');
}
Expand Down
87 changes: 77 additions & 10 deletions src/Writer/Syslog.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,17 @@ class Syslog extends AbstractWriter

/**
* Facility used by this syslog-writer instance
* @var string
* @var int
*/
protected $_facility = LOG_USER;

/**
* _validFacilities
*
* @var array
*/
protected $_validFacilities = array();

/**
* Class constructor
*
Expand All @@ -95,15 +102,21 @@ public function __construct(array $params = array())
if (isset($params['application'])) {
$this->_application = $params['application'];
}

$runInitializeSyslog = true;
if (isset($params['facility'])) {
$this->_facility = $params['facility'];
$this->_facility = $this->setFacility($params['facility']);
$runInitializeSyslog = false;
}

if ($runInitializeSyslog) {
$this->_initializeSyslog();
}
$this->_initializeSyslog();
}

/**
* Create a new instance of Zend_Log_Writer_Syslog
*
*
* @param array|\Zend\Config\Config $config
* @return \Zend\Log\Writer\Syslog
* @throws \Zend\Log\Exception
Expand All @@ -113,11 +126,45 @@ static public function factory($config = array())
return new self(self::_parseConfig($config));
}

/**
* Initialize values facilities
*
* @return void
*/
protected function _initializeValidFacilities()
{
$constants = array(
'LOG_AUTH',
'LOG_AUTHPRIV',
'LOG_CRON',
'LOG_DAEMON',
'LOG_KERN',
'LOG_LOCAL0',
'LOG_LOCAL1',
'LOG_LOCAL2',
'LOG_LOCAL3',
'LOG_LOCAL4',
'LOG_LOCAL5',
'LOG_LOCAL6',
'LOG_LOCAL7',
'LOG_LPR',
'LOG_MAIL',
'LOG_NEWS',
'LOG_SYSLOG',
'LOG_USER',
'LOG_UUCP'
);

foreach ($constants as $constant) {
if (defined($constant)) {
$this->_validFacilities[] = constant($constant);
}
}
}

/**
* Initialize syslog / set application name and facility
*
* @param string $application Application name
* @param string $facility Syslog facility
* @return void
*/
protected function _initializeSyslog()
Expand All @@ -130,16 +177,35 @@ protected function _initializeSyslog()
/**
* Set syslog facility
*
* @param string $facility Syslog facility
* @param int $facility Syslog facility
* @return void
* @throws Zend_Log_Exception for invalid log facility
*/
public function setFacility($facility)
{
if ($this->_facility === $facility) {
return;
return $this;
}

if (!count($this->_validFacilities)) {
$this->_initializeValidFacilities();
}

if (!in_array($facility, $this->_validFacilities)) {
require_once 'Zend/Log/Exception.php';
throw new Zend_Log_Exception('Invalid log facility provided; please see http://php.net/openlog for a list of valid facility values');
}

if ('WIN' == strtoupper(substr(PHP_OS, 0, 3))
&& ($facility !== LOG_USER)
) {
require_once 'Zend/Log/Exception.php';
throw new Zend_Log_Exception('Only LOG_USER is a valid log facility on Windows');
}

$this->_facility = $facility;
$this->_initializeSyslog();
return $this;
}

/**
Expand All @@ -151,10 +217,11 @@ public function setFacility($facility)
public function setApplicationName($application)
{
if ($this->_application === $application) {
return;
return $this;
}
$this->_application = $application;
$this->_initializeSyslog();
return $this;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Writer/ZendMonitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ static public function factory($config = array())
/**
* 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
* 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()
Expand Down Expand Up @@ -106,7 +106,7 @@ protected function _write($event)
unset($event['priority'], $event['message']);

if (!empty($event)) {
monitor_custom_event($priority, $message, $event);
monitor_custom_event($priority, $message, false, $event);
} else {
monitor_custom_event($priority, $message);
}
Expand Down
Loading

0 comments on commit 827c6af

Please sign in to comment.