Browse Source

ZF-8382: Zend_Log_Writer_Syslog does not utilize formatter (patch by Chris Smith)

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23551 44c647ce-9c0f-0410-b52a-842ac1e357ba
intiilapa 15 năm trước cách đây
mục cha
commit
3941aa8cd4
2 tập tin đã thay đổi với 26 bổ sung3 xóa
  1. 7 2
      library/Zend/Log/Writer/Syslog.php
  2. 19 1
      tests/Zend/Log/Writer/SyslogTest.php

+ 7 - 2
library/Zend/Log/Writer/Syslog.php

@@ -252,6 +252,11 @@ class Zend_Log_Writer_Syslog extends Zend_Log_Writer_Abstract
             $this->_initializeSyslog();
         }
 
-        syslog($priority, $event['message']);
+        $message = $event['message'];
+        if ($this->_formatter instanceof Zend_Log_Formatter_Interface) {
+            $message = $this->_formatter->format($event);
+        }
+
+        syslog($priority, $message);
     }
-}
+}

+ 19 - 1
tests/Zend/Log/Writer/SyslogTest.php

@@ -112,6 +112,24 @@ class Zend_Log_Writer_SyslogTest extends PHPUnit_Framework_TestCase
         $writer = new WriterSyslogCustom(array('facility' => LOG_USER));
         $this->assertEquals(LOG_USER, $writer->getFacility());
     }
+
+    /**
+     * @group ZF-8382
+     */
+    public function testWriteWithFormatter()
+    {
+        $event = array(
+        	'message' => 'tottakai',
+            'priority' => Zend_Log::ERR
+        );
+
+        $writer = Zend_Log_Writer_Syslog::factory(array());
+        require_once 'Zend/Log/Formatter/Simple.php';
+        $formatter = new Zend_Log_Formatter_Simple('%message% (this is a test)');
+        $writer->setFormatter($formatter);
+
+        $writer->write($event);
+    }
 }
 
 class WriterSyslogCustom extends Zend_Log_Writer_Syslog
@@ -124,4 +142,4 @@ class WriterSyslogCustom extends Zend_Log_Writer_Syslog
 
 if (PHPUnit_MAIN_METHOD == 'Zend_Log_Writer_SyslogTest::main') {
     Zend_Log_Writer_SyslogTest::main();
-}
+}