From 7c9f588354fc5633e072fb53d5a4f177a6e73de9 Mon Sep 17 00:00:00 2001 From: Kirk Madera Date: Mon, 30 Oct 2017 16:39:58 -0400 Subject: [PATCH 1/2] Removes \n or space when $context/$extra are empty Simple log messages cause extra spaces or newlines when using the default format and $context or $extra are empty, resulting in output like this: ``` 23:24:41 DEBUG [test] debug 23:24:41 INFO [test] info 23:24:41 NOTICE [test] notice 23:24:41 WARNING [test] warning 23:24:41 ERROR [test] error ``` This makes reviewing command history difficult. In the instance where $context or $extra is empty, it should not get appended with a space or newline. | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | none | License | MIT --- .../Monolog/Formatter/ConsoleFormatter.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php b/src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php index ab474c1f58e3b..1e70c1b7ab6a3 100644 --- a/src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php +++ b/src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php @@ -117,12 +117,20 @@ public function format(array $record) $levelColor = self::$levelColorMap[$record['level']]; if ($this->options['multiline']) { - $context = $extra = "\n"; + $separator = "\n"; } else { - $context = $extra = ' '; + $separator = ' '; } - $context .= $this->dumpData($record['context']); - $extra .= $this->dumpData($record['extra']); + + $context = $this->dumpData($record['context']); + if ($context) { + $context = $separator.$context; + } + + $extra = $this->dumpData($record['extra']); + if ($extra) { + $extra = $separator.$extra; + } } $formatted = strtr($this->options['format'], array( '%datetime%' => $record['datetime']->format($this->options['date_format']), From acaac1511a070e0a5db24b03e70b36a3fa6ab007 Mon Sep 17 00:00:00 2001 From: Kirk Madera Date: Mon, 30 Oct 2017 18:51:19 -0400 Subject: [PATCH 2/2] Fixed syntax error Removed extra } --- src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php b/src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php index 1e70c1b7ab6a3..00da3bdac43f5 100644 --- a/src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php +++ b/src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php @@ -130,7 +130,7 @@ public function format(array $record) $extra = $this->dumpData($record['extra']); if ($extra) { $extra = $separator.$extra; - } } + } $formatted = strtr($this->options['format'], array( '%datetime%' => $record['datetime']->format($this->options['date_format']),