From 6aebccf34ce71b1d67f975a7ef7b254d005378ee Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Sun, 8 May 2011 16:34:56 +0200 Subject: [PATCH] Moved the use of the default formatter to the getter to keep the code DRY --- src/Monolog/Handler/AbstractHandler.php | 9 +++++---- src/Monolog/Handler/MailHandler.php | 5 +---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Monolog/Handler/AbstractHandler.php b/src/Monolog/Handler/AbstractHandler.php index 0e385573..530e1f16 100644 --- a/src/Monolog/Handler/AbstractHandler.php +++ b/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; } diff --git a/src/Monolog/Handler/MailHandler.php b/src/Monolog/Handler/MailHandler.php index e7074688..c8e04990 100644 --- a/src/Monolog/Handler/MailHandler.php +++ b/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)); } }