1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-19 07:36:17 +02:00

Coding style fixes

This commit is contained in:
Jordi Boggiano
2011-03-23 23:29:33 +01:00
parent 38a4ddf9f2
commit 78d60f9dce
2 changed files with 36 additions and 39 deletions

View File

@@ -16,7 +16,7 @@ use Monolog\Logger;
/** /**
* Logs to syslog service. * Logs to syslog service.
* *
* usage example: * usage example:
* *
* $log = new Logger('application'); * $log = new Logger('application');
@@ -29,42 +29,41 @@ use Monolog\Logger;
*/ */
class SyslogHandler extends AbstractHandler class SyslogHandler extends AbstractHandler
{ {
/** /**
* Translate Monolog log levels to syslog log priorities. * Translate Monolog log levels to syslog log priorities.
*/ */
private $logLevels = array( private $logLevels = array(
Logger::DEBUG => LOG_DEBUG, Logger::DEBUG => LOG_DEBUG,
Logger::INFO => LOG_INFO, Logger::INFO => LOG_INFO,
Logger::WARNING => LOG_WARNING, Logger::WARNING => LOG_WARNING,
Logger::ERROR => LOG_ERR, Logger::ERROR => LOG_ERR,
); );
/** /**
* List of valid log facility names. * List of valid log facility names.
*/ */
private $facilities = array( private $facilities = array(
'auth' => LOG_AUTH, 'auth' => LOG_AUTH,
'authpriv' => LOG_AUTHPRIV, 'authpriv' => LOG_AUTHPRIV,
'cron' => LOG_CRON, 'cron' => LOG_CRON,
'daemon' => LOG_DAEMON, 'daemon' => LOG_DAEMON,
'kern' => LOG_KERN, 'kern' => LOG_KERN,
'local0' => LOG_LOCAL0, 'local0' => LOG_LOCAL0,
'local1' => LOG_LOCAL1, 'local1' => LOG_LOCAL1,
'local2' => LOG_LOCAL2, 'local2' => LOG_LOCAL2,
'local3' => LOG_LOCAL3, 'local3' => LOG_LOCAL3,
'local4' => LOG_LOCAL4, 'local4' => LOG_LOCAL4,
'local5' => LOG_LOCAL5, 'local5' => LOG_LOCAL5,
'local6' => LOG_LOCAL6, 'local6' => LOG_LOCAL6,
'local7' => LOG_LOCAL7, 'local7' => LOG_LOCAL7,
'lpr' => LOG_LPR, 'lpr' => LOG_LPR,
'mail' => LOG_MAIL, 'mail' => LOG_MAIL,
'news' => LOG_NEWS, 'news' => LOG_NEWS,
'syslog' => LOG_SYSLOG, 'syslog' => LOG_SYSLOG,
'user' => LOG_USER, 'user' => LOG_USER,
'uucp' => LOG_UUCP, 'uucp' => LOG_UUCP,
); );
public function __construct($ident, $facility = LOG_USER, $level = Logger::DEBUG, $bubble = true) public function __construct($ident, $facility = LOG_USER, $level = Logger::DEBUG, $bubble = true)
{ {
parent::__construct($level, $bubble); parent::__construct($level, $bubble);
@@ -73,11 +72,11 @@ class SyslogHandler extends AbstractHandler
if (array_key_exists(strtolower($facility), $this->facilities)) { if (array_key_exists(strtolower($facility), $this->facilities)) {
$facility = $this->facilities[strtolower($facility)]; $facility = $this->facilities[strtolower($facility)];
} else if (!in_array($facility, array_values($this->facilities), true)) { } else if (!in_array($facility, array_values($this->facilities), true)) {
throw new \UnexpectedValueException('unknown facility value "'.$facility.'" given'); throw new \UnexpectedValueException('Unknown facility value "'.$facility.'" given');
} }
if (!openlog($ident, LOG_PID, $facility)) { if (!openlog($ident, LOG_PID, $facility)) {
throw new \LogicException('can\'t open syslog for ident "'.$ident.'" and facility "'.$facility.'"'); throw new \LogicException('Can\'t open syslog for ident "'.$ident.'" and facility "'.$facility.'"');
} }
} }

View File

@@ -17,21 +17,19 @@ class SyslogHandlerTest extends \PHPUnit_Framework_TestCase
{ {
public function testConstruct() public function testConstruct()
{ {
$handler = new SyslogHandler('test'); $handler = new SyslogHandler('test');
$this->assertInstanceOf('Monolog\Handler\SyslogHandler', $handler); $this->assertInstanceOf('Monolog\Handler\SyslogHandler', $handler);
$handler = new SyslogHandler('test', LOG_LOCAL1); $handler = new SyslogHandler('test', LOG_LOCAL1);
$this->assertInstanceOf('Monolog\Handler\SyslogHandler', $handler); $this->assertInstanceOf('Monolog\Handler\SyslogHandler', $handler);
$handler = new SyslogHandler('test', 'local1');
$this->assertInstanceOf('Monolog\Handler\SyslogHandler', $handler);
$handler = new SyslogHandler('test', 'local1');
$this->assertInstanceOf('Monolog\Handler\SyslogHandler', $handler);
} }
public function testConstructInvalidFacility() public function testConstructInvalidFacility()
{ {
$this->setExpectedException('UnexpectedValueException'); $this->setExpectedException('UnexpectedValueException');
$handler = new SyslogHandler('test', 'unknown'); $handler = new SyslogHandler('test', 'unknown');
} }
} }