Przeglądaj źródła

Allow passing of openlog() options in SyslogHandler ctor

David Zuelke 13 lat temu
rodzic
commit
76fb21b31b

+ 2 - 2
src/Monolog/Handler/SyslogHandler.php

@@ -67,7 +67,7 @@ class SyslogHandler extends AbstractProcessingHandler
      * @param integer $level    The minimum logging level at which this handler will be triggered
      * @param Boolean $bubble   Whether the messages that are handled can bubble up the stack or not
      */
-    public function __construct($ident, $facility = LOG_USER, $level = Logger::DEBUG, $bubble = true)
+    public function __construct($ident, $facility = LOG_USER, $level = Logger::DEBUG, $bubble = true, $logopts = LOG_PID)
     {
         parent::__construct($level, $bubble);
 
@@ -89,7 +89,7 @@ class SyslogHandler extends AbstractProcessingHandler
             throw new \UnexpectedValueException('Unknown facility value "'.$facility.'" given');
         }
 
-        if (!openlog($ident, LOG_PID, $facility)) {
+        if (!openlog($ident, $logopts, $facility)) {
             throw new \LogicException('Can\'t open syslog for ident "'.$ident.'" and facility "'.$facility.'"');
         }
     }

+ 4 - 0
tests/Monolog/Handler/SyslogHandlerTest.php

@@ -10,6 +10,7 @@
  */
 
 namespace Monolog\Handler;
+use Monolog\Logger;
 
 class SyslogHandlerTest extends \PHPUnit_Framework_TestCase
 {
@@ -26,6 +27,9 @@ class SyslogHandlerTest extends \PHPUnit_Framework_TestCase
 
         $handler = new SyslogHandler('test', 'user');
         $this->assertInstanceOf('Monolog\Handler\SyslogHandler', $handler);
+
+        $handler = new SyslogHandler('test', LOG_USER, Logger::DEBUG, true, LOG_PERROR);
+        $this->assertInstanceOf('Monolog\Handler\SyslogHandler', $handler);
     }
 
     /**