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

Commit

Permalink
Merge remote branch 'upstream/master' into ZF-10246
Browse files Browse the repository at this point in the history
  • Loading branch information
Padraic Brady committed Aug 1, 2010
7 parents dea5efb + 7e2c3cc + 307038c + ce0f62a + 2d857f5 + 827c6af + b4e4ced commit 3f4a1db
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 103 deletions.
2 changes: 1 addition & 1 deletion src/Filter/Priority.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __construct($priority, $operator = \NULL)
}

$this->_priority = $priority;
$this->_operator = is_null($operator) ? '<=' : $operator;
$this->_operator = $operator === null ? '<=' : $operator;
}

/**
Expand Down
28 changes: 14 additions & 14 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ class Logger implements Factory
*
* @var string
*/
protected $_defaultWriterNamespace = '\\Zend\\Log\\Writer';
protected $_defaultWriterNamespace = 'Zend\Log\Writer';

/**
*
* @var string
*/
protected $_defaultFilterNamespace = '\\Zend\\Log\\Filter';
protected $_defaultFilterNamespace = 'Zend\Log\Filter';

/**
*
Expand Down Expand Up @@ -221,13 +221,13 @@ protected function _constructFromConfig($type, $config, $namespace)
}

$reflection = new \ReflectionClass($className);
if (!$reflection->implementsInterface('\\Zend\\Log\\Factory')) {
if (!$reflection->implementsInterface('Zend\Log\Factory')) {
throw new Exception(
'Driver does not implement Zend\\Log\\Factory and can not be constructed from config.'
'Driver does not implement Zend\Log\Factory and can not be constructed from config.'
);
}

return call_user_func(array($className, 'factory'), $params);
return $className::factory($params);
}

/**
Expand Down Expand Up @@ -449,12 +449,12 @@ public function addWriter($writer)
* @param $value Value of the field
* @return void
*/
public function setEventItem($name, $value)
public function setEventItem($name, $value)
{
$this->_extras = array_merge($this->_extras, array($name => $value));
return $this;
}

/**
* Register Logging system as an error handler to log php errors
* Note: it still calls the original error handler if set_error_handler is able to return it.
Expand All @@ -473,12 +473,12 @@ public function setEventItem($name, $value)
public function registerErrorHandler()
{
// Only register once. Avoids loop issues if it gets registered twice.
if ($this->_registeredErrorHandler) {
return $this;
if ($this->_registeredErrorHandler) {
return $this;
}

$this->_origErrorHandler = set_error_handler(array($this, 'errorHandler'));

// Contruct a default map of phpErrors to Zend_Log priorities.
// Some of the errors are uncatchable, but are included for completeness
$this->_errorHandlerMap = array(
Expand All @@ -499,7 +499,7 @@ public function registerErrorHandler()
$this->_registeredErrorHandler = true;
return $this;
}

/**
* Error Handler will convert error into log message, and then call the original error handler
*
Expand All @@ -514,7 +514,7 @@ public function registerErrorHandler()
public function errorHandler($errno, $errstr, $errfile, $errline, $errcontext)
{
$errorLevel = error_reporting();

if ($errorLevel && $errno) {
if (isset($this->_errorHandlerMap[$errno])) {
$priority = $this->_errorHandlerMap[$errno];
Expand All @@ -523,7 +523,7 @@ public function errorHandler($errno, $errstr, $errfile, $errline, $errcontext)
}
$this->log($errstr, $priority, array('errno'=>$errno, 'file'=>$errfile, 'line'=>$errline, 'context'=>$errcontext));
}

if ($this->_origErrorHandler !== null) {
return call_user_func($this->_origErrorHandler, $errno, $errstr, $errfile, $errline, $errcontext);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function addFilter($filter);
* @param \Zend\Log\Formatter|Callable $formatter
* @return Writer
*/
public function setFormatter($formatter);
public function setFormatter(Formatter $formatter);

/**
* Write a log message
Expand Down
4 changes: 2 additions & 2 deletions src/Writer/AbstractWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function write($event)
* @param \Zend\Log\Formatter $formatter
* @return void
*/
public function setFormatter($formatter)
public function setFormatter(\Zend\Log\Formatter $formatter)
{
$this->_formatter = $formatter;
return $this;
Expand All @@ -120,7 +120,7 @@ abstract protected function _write($event);

/**
* Validate and optionally convert the config to array
*
*
* @param array|\Zend\Config\Config $config \Zend\Config\Config or Array
* @return array
* @throws \Zend\Log\Exception
Expand Down
6 changes: 2 additions & 4 deletions src/Writer/Syslog.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,13 @@ public function setFacility($facility)
}

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');
throw new 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');
throw new Log\Exception('Only LOG_USER is a valid log facility on Windows');
}

$this->_facility = $facility;
Expand Down
54 changes: 27 additions & 27 deletions test/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function testAddWriterAddsMultipleWriters()

public function testLoggerThrowsWhenNoWriters()
{
$this->setExpectedException('\\Zend\\Log\\Exception', 'No writers');
$this->setExpectedException('Zend\Log\Exception', 'No writers');
$logger = new Logger();
$logger->log('message', Logger::INFO);
}
Expand Down Expand Up @@ -125,21 +125,21 @@ public function testLogThrowsOnBadLogPriority()
{
$logger = new Logger($this->writer);

$this->setExpectedException('\\Zend\\Log\\Exception', 'Bad log priority');
$this->setExpectedException('Zend\Log\Exception', 'Bad log priority');
$logger->log('foo', 42);
}

public function testLogThrough__callThrowsOnBadLogPriority()
{
$logger = new Logger($this->writer);

$this->setExpectedException('\\Zend\\Log\\Exception', 'Bad log priority');
$this->setExpectedException('Zend\Log\Exception', 'Bad log priority');
$logger->nonexistantPriority('');
}

public function testAddingPriorityThrowsWhenOverridingBuiltinLogPriority()
{
$this->setExpectedException('\\Zend\\Log\\Exception', 'Existing priorities');
$this->setExpectedException('Zend\Log\Exception', 'Existing priorities');
$logger = new Logger($this->writer);
$logger->addPriority('BOB', 0);
}
Expand Down Expand Up @@ -222,14 +222,14 @@ public function testLogAcceptsExtrasParameterAsScalarAndAddsAsInfoKeyToEvent()
$info = $event['info'];
$this->assertContains('nonesuch', $info);
}

// Factory

public function testLogConstructFromConfigStream()
{
$cfg = array('log' => array('memory' => array(
'writerName' => "Stream",
'writerNamespace' => "\\Zend\\Log\\Writer",
'writerNamespace' => "Zend\Log\Writer",
'writerParams' => array(
'stream' => "php://memory"
)
Expand All @@ -243,13 +243,13 @@ public function testLogConstructFromConfigStreamAndFilter()
{
$cfg = array('log' => array('memory' => array(
'writerName' => "Stream",
'writerNamespace' => "\\Zend\\Log\\Writer",
'writerNamespace' => "Zend\Log\Writer",
'writerParams' => array(
'stream' => "php://memory"
),
'filterName' => "Priority",
'filterParams' => array(
'priority' => "\\Zend\\Log\\Logger::CRIT",
'priority' => "Zend\Log\Logger::CRIT",
'operator' => "<="
),
)));
Expand All @@ -262,7 +262,7 @@ public function testFactoryUsesNameAndNamespaceWithoutModifications()
{
$cfg = array('log' => array('memory' => array(
'writerName' => "ZendMonitor",
'writerNamespace' => "\\Zend\\Log\\Writer",
'writerNamespace' => "Zend\Log\Writer",
)));

$logger = Logger::factory($cfg['log']);
Expand All @@ -279,36 +279,36 @@ public function testUsingWithErrorHandler()
$logger = new Logger();
$logger->addWriter($writer);
$this->errWriter = $writer;


$oldErrorLevel = error_reporting();

$this->expectingLogging = true;
error_reporting(E_ALL | E_STRICT);

$oldHandler = set_error_handler(array($this, 'verifyHandlerData'));
$logger->registerErrorHandler();

trigger_error("Testing notice shows up in logs", E_USER_NOTICE);
trigger_error("Testing warning shows up in logs", E_USER_WARNING);
trigger_error("Testing error shows up in logs", E_USER_ERROR);

$this->expectingLogging = false;
error_reporting(0);

trigger_error("Testing notice misses logs", E_USER_NOTICE);
trigger_error("Testing warning misses logs", E_USER_WARNING);
trigger_error("Testing error misses logs", E_USER_ERROR);

restore_error_handler(); // Pop off the Logger
restore_error_handler(); // Pop off the verifyHandlerData
error_reporting($oldErrorLevel); // Restore original reporting level
unset($this->errWriter);
}

/**
* @group ZF-9192
* Used by testUsingWithErrorHandler -
* Used by testUsingWithErrorHandler -
* verifies that the data written to the original logger is the same as the data written in Zend_Log
*/
public function verifyHandlerData($errno, $errstr, $errfile, $errline, $errcontext)
Expand Down Expand Up @@ -384,37 +384,37 @@ public function testExceptionConstructFilterFromConfig()
*/
public function testFluentInterface()
{
$logger = new Zend_Log();
$logger = new Logger();
$instance = $logger->addPriority('all', 8)
->addFilter(1)
->addWriter(array('writerName' => 'Null'))
->setEventItem('os', PHP_OS);

$this->assertTrue($instance instanceof Zend_Log);
$this->assertTrue($instance instanceof Logger);
}

/**
* @group ZF-10170
*/
public function testPriorityDuplicates()
{
$logger = new Zend_Log();
$mock = new Zend_Log_Writer_Mock();
$logger = new Logger();
$mock = new Log\Writer\Mock();
$logger->addWriter($mock);
try {
$logger->addPriority('emerg', 8);
$this->fail();
} catch(Exception $e) {
$this->assertType('Zend_Log_Exception', $e);
} catch(\Exception $e) {
$this->assertType('Zend\Log\Exception', $e);
$this->assertEquals('Existing priorities cannot be overwritten', $e->getMessage());
}

try {
$logger->log('zf10170', 0);
$logger->log('clone zf10170', 8);
$this->fail();
} catch (Exception $e) {
$this->assertType('Zend_Log_Exception', $e);
} catch (\Exception $e) {
$this->assertType('Zend\Log\Exception', $e);
$this->assertEquals('Bad log priority', $e->getMessage());
}
$this->assertEquals(0, $mock->events[0]['priority']);
Expand Down
15 changes: 15 additions & 0 deletions test/TestAsset/ConcreteWriter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
namespace ZendTest\Log\TestAsset;

use Zend\Log\Writer\AbstractWriter;

class ConcreteWriter extends AbstractWriter
{
protected function _write($event)
{
}

static public function factory($config = array())
{
}
}
Loading

0 comments on commit 3f4a1db

Please sign in to comment.