2
0
Эх сурвалжийг харах

Change Logger::setTimezone to accept a DateTimeZone object, refs #566

Jordi Boggiano 10 жил өмнө
parent
commit
8c4b1be4a2

+ 6 - 4
src/Monolog/Logger.php

@@ -443,7 +443,7 @@ class Logger implements LoggerInterface
     public function log($level, $message, array $context = array())
     public function log($level, $message, array $context = array())
     {
     {
         $level = static::toMonologLevel($level);
         $level = static::toMonologLevel($level);
-        
+
         return $this->addRecord($level, $message, $context);
         return $this->addRecord($level, $message, $context);
     }
     }
 
 
@@ -618,10 +618,12 @@ class Logger implements LoggerInterface
     /**
     /**
      * Set the timezone to be used for the timestamp of log records.
      * Set the timezone to be used for the timestamp of log records.
      *
      *
-     * @param string $tz Timezone name
+     * This is stored globally for all Logger instances
+     *
+     * @param \DateTimeZone $tz Timezone object
      */
      */
-    public static function setTimezone($tz)
+    public static function setTimezone(\DateTimeZone $tz)
     {
     {
-        self::$timezone = new \DateTimeZone($tz);
+        self::$timezone = $tz;
     }
     }
 }
 }

+ 2 - 2
tests/Monolog/LoggerTest.php

@@ -434,13 +434,13 @@ class LoggerTest extends \PHPUnit_Framework_TestCase
         $logger->pushHandler($handler);
         $logger->pushHandler($handler);
         $logger->info('test');
         $logger->info('test');
         list($record) = $handler->getRecords();
         list($record) = $handler->getRecords();
-        $this->assertEquals($tz, $record['datetime']->getTimezone()->getName());
+        $this->assertEquals($tz, $record['datetime']->getTimezone());
     }
     }
 
 
     public function setTimezoneProvider()
     public function setTimezoneProvider()
     {
     {
         return array_map(
         return array_map(
-            function ($tz) { return array($tz); },
+            function ($tz) { return array(new \DateTimeZone($tz)); },
             \DateTimeZone::listIdentifiers()
             \DateTimeZone::listIdentifiers()
         );
         );
     }
     }