From ccb4aeba216f8ad60a00ddea3fe823dbce4dc4b1 Mon Sep 17 00:00:00 2001 From: Pavel Golovin Date: Mon, 10 Oct 2016 18:57:57 +0300 Subject: [PATCH 1/2] Remove substitution for not defined variables If variable in extra or context isn't defined, than placeholder will not not be replaced in format string. This patch remove all not replaced placeholders --- src/Monolog/Formatter/LineFormatter.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Monolog/Formatter/LineFormatter.php b/src/Monolog/Formatter/LineFormatter.php index 0e62aa35..554fff6e 100644 --- a/src/Monolog/Formatter/LineFormatter.php +++ b/src/Monolog/Formatter/LineFormatter.php @@ -76,6 +76,8 @@ class LineFormatter extends NormalizerFormatter } } + $output = preg_replace('/%extra\..+?%/', '', $output); + foreach ($vars['context'] as $var => $val) { if (false !== strpos($output, '%context.'.$var.'%')) { $output = str_replace('%context.'.$var.'%', $this->stringify($val), $output); @@ -83,6 +85,8 @@ class LineFormatter extends NormalizerFormatter } } + $output = preg_replace('/%context\..+?%/', '', $output); + if ($this->ignoreEmptyContextAndExtra) { if (empty($vars['context'])) { unset($vars['context']); From c3c0abf2a42e2e9575246ea52f84e2249642d0a3 Mon Sep 17 00:00:00 2001 From: Pavel Golovin Date: Mon, 10 Oct 2016 19:01:08 +0300 Subject: [PATCH 2/2] Update LineFormatter.php --- src/Monolog/Formatter/LineFormatter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Monolog/Formatter/LineFormatter.php b/src/Monolog/Formatter/LineFormatter.php index 554fff6e..7122319d 100644 --- a/src/Monolog/Formatter/LineFormatter.php +++ b/src/Monolog/Formatter/LineFormatter.php @@ -76,7 +76,7 @@ class LineFormatter extends NormalizerFormatter } } - $output = preg_replace('/%extra\..+?%/', '', $output); + $output = preg_replace('/%extra\..+?%/', '', $output); foreach ($vars['context'] as $var => $val) { if (false !== strpos($output, '%context.'.$var.'%')) { @@ -85,7 +85,7 @@ class LineFormatter extends NormalizerFormatter } } - $output = preg_replace('/%context\..+?%/', '', $output); + $output = preg_replace('/%context\..+?%/', '', $output); if ($this->ignoreEmptyContextAndExtra) { if (empty($vars['context'])) {