bug #28471 [MonologBridge] Re-add option option to ignore empty context and extra data (mpdude)

This PR was squashed before being merged into the 3.4 branch (closes #28471).

Discussion
----------

[MonologBridge] Re-add option option to ignore empty context and extra data

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

In #11496, an option was added to `ConsoleFormatter` to ignore empty context and extra data. This setting was even turned on by default.

The `ConsoleHandler` was then overhauled in #21705. During this change, the option got lost.

Commits
-------

d1e7438605 [MonologBridge] Re-add option option to ignore empty context and extra data
This commit is contained in:
Nicolas Grekas 2018-09-20 13:58:14 +02:00
commit 31e96f7435
2 changed files with 14 additions and 14 deletions

View File

@ -69,6 +69,9 @@ class ConsoleFormatter implements FormatterInterface
if (isset($args[2])) { if (isset($args[2])) {
$options['multiline'] = $args[2]; $options['multiline'] = $args[2];
} }
if (isset($args[3])) {
$options['ignore_empty_context_and_extra'] = $args[3];
}
} }
$this->options = array_replace(array( $this->options = array_replace(array(
@ -76,6 +79,7 @@ class ConsoleFormatter implements FormatterInterface
'date_format' => self::SIMPLE_DATE, 'date_format' => self::SIMPLE_DATE,
'colors' => true, 'colors' => true,
'multiline' => false, 'multiline' => false,
'ignore_empty_context_and_extra' => true,
), $options); ), $options);
if (class_exists(VarCloner::class)) { if (class_exists(VarCloner::class)) {
@ -116,20 +120,16 @@ class ConsoleFormatter implements FormatterInterface
$levelColor = self::$levelColorMap[$record['level']]; $levelColor = self::$levelColorMap[$record['level']];
if ($this->options['multiline']) { if (!$this->options['ignore_empty_context_and_extra'] || !empty($record['context'])) {
$separator = "\n"; $context = ($this->options['multiline'] ? "\n" : ' ').$this->dumpData($record['context']);
} else { } else {
$separator = ' '; $context = '';
} }
$context = $this->dumpData($record['context']); if (!$this->options['ignore_empty_context_and_extra'] || !empty($record['extra'])) {
if ($context) { $extra = ($this->options['multiline'] ? "\n" : ' ').$this->dumpData($record['extra']);
$context = $separator.$context; } else {
} $extra = '';
$extra = $this->dumpData($record['extra']);
if ($extra) {
$extra = $separator.$extra;
} }
$formatted = strtr($this->options['format'], array( $formatted = strtr($this->options['format'], array(

View File

@ -64,9 +64,9 @@ class ConsoleHandlerTest extends TestCase
$realOutput = $this->getMockBuilder('Symfony\Component\Console\Output\Output')->setMethods(array('doWrite'))->getMock(); $realOutput = $this->getMockBuilder('Symfony\Component\Console\Output\Output')->setMethods(array('doWrite'))->getMock();
$realOutput->setVerbosity($verbosity); $realOutput->setVerbosity($verbosity);
if ($realOutput->isDebug()) { if ($realOutput->isDebug()) {
$log = "16:21:54 $levelName [app] My info message\n[]\n[]\n"; $log = "16:21:54 $levelName [app] My info message\n";
} else { } else {
$log = "16:21:54 $levelName [app] My info message [] []\n"; $log = "16:21:54 $levelName [app] My info message\n";
} }
$realOutput $realOutput
->expects($isHandling ? $this->once() : $this->never()) ->expects($isHandling ? $this->once() : $this->never())
@ -149,7 +149,7 @@ class ConsoleHandlerTest extends TestCase
$output $output
->expects($this->once()) ->expects($this->once())
->method('write') ->method('write')
->with("16:21:54 <fg=green>INFO </> <comment>[app]</> My info message\n[]\n[]\n") ->with("16:21:54 <fg=green>INFO </> <comment>[app]</> My info message\n")
; ;
$handler = new ConsoleHandler(null, false); $handler = new ConsoleHandler(null, false);