소스 검색

Merge pull request #279 from upyx/master

Fix boolean to string convertation. Fix double normalization.
Jordi Boggiano 12 년 전
부모
커밋
5ad421d6a1
2개의 변경된 파일17개의 추가작업 그리고 18개의 파일을 삭제
  1. 14 17
      src/Monolog/Formatter/LineFormatter.php
  2. 3 1
      tests/Monolog/Formatter/LineFormatterTest.php

+ 14 - 17
src/Monolog/Formatter/LineFormatter.php

@@ -11,6 +11,8 @@
 
 namespace Monolog\Formatter;
 
+use Exception;
+
 /**
  * Formats incoming records into a one-line string
  *
@@ -68,33 +70,28 @@ class LineFormatter extends NormalizerFormatter
         return $message;
     }
 
-    protected function normalize($data)
+    protected function normalizeException(Exception $e)
     {
-        if (is_bool($data) || is_null($data)) {
-            return var_export($data, true);
+        $previousText = '';
+        if ($previous = $e->getPrevious()) {
+            do {
+                $previousText .= ', '.get_class($previous).': '.$previous->getMessage().' at '.$previous->getFile().':'.$previous->getLine();
+            } while ($previous = $previous->getPrevious());
         }
 
-        if ($data instanceof \Exception) {
-            $previousText = '';
-            if ($previous = $data->getPrevious()) {
-                do {
-                    $previousText .= ', '.get_class($previous).': '.$previous->getMessage().' at '.$previous->getFile().':'.$previous->getLine();
-                } while ($previous = $previous->getPrevious());
-            }
-
-            return '[object] ('.get_class($data).': '.$data->getMessage().' at '.$data->getFile().':'.$data->getLine().$previousText.')';
-        }
-
-        return parent::normalize($data);
+        return '[object] ('.get_class($e).': '.$e->getMessage().' at '.$e->getFile().':'.$e->getLine().$previousText.')';
     }
 
     protected function convertToString($data)
     {
-        if (null === $data || is_scalar($data)) {
+        if (null === $data || is_bool($data)) {
+            return var_export($data, true);
+        }
+
+        if (is_scalar($data)) {
             return (string) $data;
         }
 
-        $data = $this->normalize($data);
         if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
             return $this->toJson($data, true);
         }

+ 3 - 1
tests/Monolog/Formatter/LineFormatterTest.php

@@ -42,9 +42,11 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase
             'context' => array(
                 'foo' => 'bar',
                 'baz' => 'qux',
+                'bool' => false,
+                'null' => null,
             )
         ));
-        $this->assertEquals('['.date('Y-m-d').'] meh.ERROR: foo {"foo":"bar","baz":"qux"} []'."\n", $message);
+        $this->assertEquals('['.date('Y-m-d').'] meh.ERROR: foo {"foo":"bar","baz":"qux","bool":false,"null":null} []'."\n", $message);
     }
 
     public function testDefFormatExtras()