Skip to content

Commit cb6c394

Browse files
committed
bug symfony#24759 Removes \n or space when $context/$extra are empty (kirkmadera)
This PR was squashed before being merged into the 3.3 branch (closes symfony#24759). Discussion ---------- 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 Commits ------- 0d8edae Removes \n or space when / are empty
2 parents ca10f8e + 0d8edae commit cb6c394

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,20 @@ public function format(array $record)
117117
$levelColor = self::$levelColorMap[$record['level']];
118118

119119
if ($this->options['multiline']) {
120-
$context = $extra = "\n";
120+
$separator = "\n";
121121
} else {
122-
$context = $extra = ' ';
122+
$separator = ' ';
123+
}
124+
125+
$context = $this->dumpData($record['context']);
126+
if ($context) {
127+
$context = $separator.$context;
128+
}
129+
130+
$extra = $this->dumpData($record['extra']);
131+
if ($extra) {
132+
$extra = $separator.$extra;
123133
}
124-
$context .= $this->dumpData($record['context']);
125-
$extra .= $this->dumpData($record['extra']);
126134

127135
$formatted = strtr($this->options['format'], array(
128136
'%datetime%' => $record['datetime']->format($this->options['date_format']),

0 commit comments

Comments
 (0)