ソースを参照

ZF-10990: Zend_Log::factory() doesn't support options like timestampFormat

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23744 44c647ce-9c0f-0410-b52a-842ac1e357ba
intiilapa 15 年 前
コミット
80f38e2a84

+ 6 - 0
documentation/manual/en/module_specs/Zend_Log-Factory.xml

@@ -17,6 +17,7 @@
 
     <programlisting language="php"><![CDATA[
 $logger = Zend_Log::factory(array(
+    'timestampFormat' => 'Y-m-d',
     array(
         'writerName'   => 'Stream',
         'writerParams' => array(
@@ -48,6 +49,11 @@ $logger = Zend_Log::factory(array(
     </para>
 
     <para>
+        By default, events are logged with the ISO 8601 date format. You can choose your own format
+        with the option <emphasis>timestampFormat</emphasis>.
+    </para>
+
+    <para>
         Each writer can be defined with the following keys:
     </para>
 

+ 7 - 1
documentation/manual/fr/module_specs/Zend_Log-Factory.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- EN-Revision: 23739 -->
+<!-- EN-Revision: 23743 -->
 <!-- Reviewed: no -->
 <sect1 id="zend.log.factory">
     <title>Utiliser la fabrique pour créer des logs</title>
@@ -18,6 +18,7 @@
 
     <programlisting language="php"><![CDATA[
 $logger = Zend_Log::factory(array(
+    'timestampFormat' => 'Y-m-d',
     array(
         'writerName'   => 'Stream',
         'writerParams' => array(
@@ -49,6 +50,11 @@ $logger = Zend_Log::factory(array(
     </para>
 
     <para>
+        Les évènements sont journalisés avec le format de date ISO 8601 par défaut. Vous
+        pouvez choisir votre propre format avec l'option <emphasis>timestampFormat</emphasis>.
+    </para>
+
+    <para>
         Chaque objet d'écriture support les options suivantes:
     </para>
 

+ 7 - 0
library/Zend/Log.php

@@ -138,6 +138,13 @@ class Zend_Log
 
         $log = new self;
 
+        if (array_key_exists('timestampFormat', $config)) {
+            if (null != $config['timestampFormat'] && '' != $config['timestampFormat']) {
+                $log->setTimestampFormat($config['timestampFormat']);
+            }
+            unset($config['timestampFormat']);
+        }
+
         if (!is_array(current($config))) {
             $log->addWriter(current($config));
         } else {

+ 32 - 0
tests/Zend/Log/LogTest.php

@@ -491,6 +491,38 @@ class Zend_Log_LogTest extends PHPUnit_Framework_TestCase
         $logger = Zend_Log::factory($config['log']);
         $logger->log('custom message', Zend_Log::INFO);
     }
+
+    /**
+     * @group ZF-10990
+     */
+    public function testFactoryShouldSetTimestampFormat()
+    {
+        $config = array(
+            'timestampFormat' => 'Y-m-d',
+            'mock' => array(
+                'writerName' => 'Mock'
+            )
+        );
+        $logger = Zend_Log::factory($config);
+
+        $this->assertEquals('Y-m-d', $logger->getTimestampFormat());
+    }
+
+    /**
+     * @group ZF-10990
+     */
+    public function testFactoryShouldKeepDefaultTimestampFormat()
+    {
+        $config = array(
+            'timestampFormat' => '',
+            'mock' => array(
+                'writerName' => 'Mock'
+            )
+        );
+        $logger = Zend_Log::factory($config);
+
+        $this->assertEquals('c', $logger->getTimestampFormat());
+    }
 }
 
 class Zend_Log_Writer_NotExtendedWriterAbstract implements Zend_Log_FactoryInterface