Просмотр исходного кода

Syslog: moving LOG_LOCAL* out into the constructor for windows compat'

Jordi Boggiano 15 лет назад
Родитель
Сommit
d178bdce01
2 измененных файлов с 13 добавлено и 10 удалено
  1. 11 8
      src/Monolog/Handler/SyslogHandler.php
  2. 2 2
      tests/Monolog/Handler/SyslogHandlerTest.php

+ 11 - 8
src/Monolog/Handler/SyslogHandler.php

@@ -48,14 +48,6 @@ class SyslogHandler extends AbstractHandler
         'cron'     => LOG_CRON,
         'daemon'   => LOG_DAEMON,
         'kern'     => LOG_KERN,
-        'local0'   => LOG_LOCAL0,
-        'local1'   => LOG_LOCAL1,
-        'local2'   => LOG_LOCAL2,
-        'local3'   => LOG_LOCAL3,
-        'local4'   => LOG_LOCAL4,
-        'local5'   => LOG_LOCAL5,
-        'local6'   => LOG_LOCAL6,
-        'local7'   => LOG_LOCAL7,
         'lpr'      => LOG_LPR,
         'mail'     => LOG_MAIL,
         'news'     => LOG_NEWS,
@@ -68,6 +60,17 @@ class SyslogHandler extends AbstractHandler
     {
         parent::__construct($level, $bubble);
 
+        if (false === strpos(PHP_OS, 'WIN')) {
+            $this->facilities['local0'] = LOG_LOCAL0;
+            $this->facilities['local1'] = LOG_LOCAL1;
+            $this->facilities['local2'] = LOG_LOCAL2;
+            $this->facilities['local3'] = LOG_LOCAL3;
+            $this->facilities['local4'] = LOG_LOCAL4;
+            $this->facilities['local5'] = LOG_LOCAL5;
+            $this->facilities['local6'] = LOG_LOCAL6;
+            $this->facilities['local7'] = LOG_LOCAL7;
+        }
+
         // convert textual description of facility to syslog constant
         if (array_key_exists(strtolower($facility), $this->facilities)) {
             $facility = $this->facilities[strtolower($facility)];

+ 2 - 2
tests/Monolog/Handler/SyslogHandlerTest.php

@@ -20,10 +20,10 @@ class SyslogHandlerTest extends \PHPUnit_Framework_TestCase
         $handler = new SyslogHandler('test');
         $this->assertInstanceOf('Monolog\Handler\SyslogHandler', $handler);
 
-        $handler = new SyslogHandler('test', LOG_LOCAL1);
+        $handler = new SyslogHandler('test', LOG_USER);
         $this->assertInstanceOf('Monolog\Handler\SyslogHandler', $handler);
 
-        $handler = new SyslogHandler('test', 'local1');
+        $handler = new SyslogHandler('test', 'user');
         $this->assertInstanceOf('Monolog\Handler\SyslogHandler', $handler);
     }