Просмотр исходного кода

Moved the use of the default formatter to the getter to keep the code DRY

Christophe Coevoet 14 лет назад
Родитель
Сommit
6aebccf34c
2 измененных файлов с 6 добавлено и 8 удалено
  1. 5 4
      src/Monolog/Handler/AbstractHandler.php
  2. 1 4
      src/Monolog/Handler/MailHandler.php

+ 5 - 4
src/Monolog/Handler/AbstractHandler.php

@@ -62,10 +62,7 @@ abstract class AbstractHandler implements HandlerInterface
 
         $record = $this->processRecord($record);
 
-        if (!$this->formatter) {
-            $this->formatter = $this->getDefaultFormatter();
-        }
-        $record['message'] = $this->formatter->format($record);
+        $record['message'] = $this->getFormatter()->format($record);
 
         $this->write($record);
 
@@ -120,6 +117,10 @@ abstract class AbstractHandler implements HandlerInterface
      */
     public function getFormatter()
     {
+        if (!$this->formatter) {
+            $this->formatter = $this->getDefaultFormatter();
+        }
+
         return $this->formatter;
     }
 

+ 1 - 4
src/Monolog/Handler/MailHandler.php

@@ -33,10 +33,7 @@ abstract class MailHandler extends AbstractHandler
         }
 
         if (!empty($messages)) {
-            if (!$this->formatter) {
-                $this->formatter = $this->getDefaultFormatter();
-            }
-            $this->send($this->formatter->formatBatch($messages));
+            $this->send($this->getFormatter()->formatBatch($messages));
         }
     }