Skip to content

Commit e9a2c3d

Browse files
committed
feature symfony#30345 [Monolog] Added a way to configure the ConsoleFormatter from the ConsoleHandler (lyrixx)
This PR was merged into the 4.3-dev branch. Discussion ---------- [Monolog] Added a way to configure the ConsoleFormatter from the ConsoleHandler | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | see also symfony/monolog-bundle#297 from that: ![image](https://user-images.githubusercontent.com/408368/53246085-f63ed380-36af-11e9-9bff-2e42f8af141c.png) to that: ![image](https://user-images.githubusercontent.com/408368/53246115-0787e000-36b0-11e9-93ef-e47ed058adbf.png) with some configuration: ```yaml diff --git a/config/packages/dev/monolog.yaml b/config/packages/dev/monolog.yaml index b1998da..66ae2db 100644 --- a/config/packages/dev/monolog.yaml +++ b/config/packages/dev/monolog.yaml @@ -17,3 +17,6 @@ monolog: type: console process_psr_3_messages: false channels: ["!event", "!doctrine", "!console"] + console_formater_options: + format: "%%datetime%% %%start_tag%%%%level_name%%%%end_tag%% <comment>[%%channel%%]</> %%message%%%%context%%\n" + multiline: false ``` Commits ------- 5e494db [Monolog] Added a way to configure the ConsoleFormatter from the ConsoleHandler
2 parents 5f8aa34 + 5e494db commit e9a2c3d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/Symfony/Bridge/Monolog/Handler/ConsoleHandler.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class ConsoleHandler extends AbstractProcessingHandler implements EventSubscribe
5050
OutputInterface::VERBOSITY_VERY_VERBOSE => Logger::INFO,
5151
OutputInterface::VERBOSITY_DEBUG => Logger::DEBUG,
5252
];
53+
private $consoleFormaterOptions;
5354

5455
/**
5556
* @param OutputInterface|null $output The console output to use (the handler remains disabled when passing null
@@ -58,14 +59,16 @@ class ConsoleHandler extends AbstractProcessingHandler implements EventSubscribe
5859
* @param array $verbosityLevelMap Array that maps the OutputInterface verbosity to a minimum logging
5960
* level (leave empty to use the default mapping)
6061
*/
61-
public function __construct(OutputInterface $output = null, bool $bubble = true, array $verbosityLevelMap = [])
62+
public function __construct(OutputInterface $output = null, bool $bubble = true, array $verbosityLevelMap = [], array $consoleFormaterOptions = [])
6263
{
6364
parent::__construct(Logger::DEBUG, $bubble);
6465
$this->output = $output;
6566

6667
if ($verbosityLevelMap) {
6768
$this->verbosityLevelMap = $verbosityLevelMap;
6869
}
70+
71+
$this->consoleFormaterOptions = $consoleFormaterOptions;
6972
}
7073

7174
/**
@@ -155,13 +158,13 @@ protected function getDefaultFormatter()
155158
return new LineFormatter();
156159
}
157160
if (!$this->output) {
158-
return new ConsoleFormatter();
161+
return new ConsoleFormatter($this->consoleFormaterOptions);
159162
}
160163

161-
return new ConsoleFormatter([
164+
return new ConsoleFormatter(array_replace([
162165
'colors' => $this->output->isDecorated(),
163166
'multiline' => OutputInterface::VERBOSITY_DEBUG <= $this->output->getVerbosity(),
164-
]);
167+
], $this->consoleFormaterOptions));
165168
}
166169

167170
/**

0 commit comments

Comments
 (0)