8000 [MonologBridge] Re-add option option to ignore empty context and extr… · symfony/symfony@d1e7438 · GitHub
[go: up one dir, main page]

Skip to content

Commit d1e7438

Browse files
mpdudenicolas-grekas
authored andcommitted
[MonologBridge] Re-add option option to ignore empty context and extra data
1 parent b4bbc25 commit d1e7438

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,17 @@ public function __construct($options = array())
6969
if (isset($args[2])) {
7070
$options['multiline'] = $args[2];
7171
}
72+
if (isset($args[3])) {
73+
$options['ignore_empty_context_and_extra'] = $args[3];
74+
}
7275
}
7376

7477
$this->options = array_replace(array(
7578
'format' => self::SIMPLE_FORMAT,
7679
'date_format' => self::SIMPLE_DATE,
7780
'colors' => true,
7881
'multiline' => false,
82+
'ignore_empty_context_and_extra' => true,
7983
), $options);
8084

8185
if (class_exists(VarCloner::class)) {
@@ -116,20 +120,16 @@ public function format(array $record)
116120

117121
$levelColor = self::$levelColorMap[$record['level']];
118122

119-
if ($this->options['multiline']) {
120-
$separator = "\n";
123+
if (!$this->options['ignore_empty_context_and_extra'] || !empty($record['context'])) {
124+
$context = ($this->options['multiline'] ? "\n" : ' ').$this->dumpData($record['context']);
121125
} else {
122-
$separator = ' ';
126+
$context = '';
123127
}
124128

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;
129+
if (!$this->options['ignore_empty_context_and_extra'] || !empty($record['extra'])) {
130+
$extra = ($this->options['multiline'] ? "\n" : ' ').$this->dumpData($record['extra']);
131+
} else {
132+
$extra = '';
133133
}
134134

135135
$formatted = strtr($this->options['format'], array(

src/Symfony/Bridge/Monolog/Tests/Handler/ConsoleHandlerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ public function testVerbosityMapping($verbosity, $level, $isHandling, array $map
6464
$realOutput = $this->getMockBuilder('Symfony\Component\Console\Output\Output')->setMethods(array('doWrite'))->getMock();
6565
$realOutput->setVerbosity($verbosity);
6666
if ($realOutput->isDebug()) {
67-
$log = "16:21:54 $levelName [app] My info message\n[]\n[]\n";
67+
$log = "16:21:54 $levelName [app] My info message\n";
6868
} else {
69-
$log = "16:21:54 $levelName [app] My info message [] []\n";
69+
$log = "16:21:54 $levelName [app] My info message\n";
7070
}
7171
$realOutput
7272
->expects($isHandling ? $this->once() : $this->never())
@@ -149,7 +149,7 @@ public function testWritingAndFormatting()
149149
$output
150150
->expects($this->once())
151151
->method('write')
152-
->with("16:21:54 <fg=green>INFO </> <comment>[app]</> My info message\n[]\n[]\n")
152+
->with("16:21:54 <fg=green>INFO </> <comment>[app]</> My info message\n")
153153
;
154154

155155
$handler = new ConsoleHandler(null, false);

0 commit comments

Comments
 (0)
0