Skip to content
Permalink
Browse files

feature #30345 [Monolog] Added a way to configure the ConsoleFormatte…

…r 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
  • Loading branch information...
fabpot committed Feb 23, 2019
2 parents 5f8aa34 + 5e494db commit e9a2c3d7538a2700aa40b2bec15ffb31d9180096
Showing with 7 additions and 4 deletions.
  1. +7 −4 src/Symfony/Bridge/Monolog/Handler/ConsoleHandler.php
@@ -50,6 +50,7 @@ class ConsoleHandler extends AbstractProcessingHandler implements EventSubscribe
OutputInterface::VERBOSITY_VERY_VERBOSE => Logger::INFO,
OutputInterface::VERBOSITY_DEBUG => Logger::DEBUG,
];
private $consoleFormaterOptions;
/**
* @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
* @param array $verbosityLevelMap Array that maps the OutputInterface verbosity to a minimum logging
* level (leave empty to use the default mapping)
*/
public function __construct(OutputInterface $output = null, bool $bubble = true, array $verbosityLevelMap = [])
public function __construct(OutputInterface $output = null, bool $bubble = true, array $verbosityLevelMap = [], array $consoleFormaterOptions = [])
{
parent::__construct(Logger::DEBUG, $bubble);
$this->output = $output;
if ($verbosityLevelMap) {
$this->verbosityLevelMap = $verbosityLevelMap;
}
$this->consoleFormaterOptions = $consoleFormaterOptions;
}
/**
@@ -155,13 +158,13 @@ protected function getDefaultFormatter()
return new LineFormatter();
}
if (!$this->output) {
return new ConsoleFormatter();
return new ConsoleFormatter($this->consoleFormaterOptions);
}
return new ConsoleFormatter([
return new ConsoleFormatter(array_replace([
'colors' => $this->output->isDecorated(),
'multiline' => OutputInterface::VERBOSITY_DEBUG <= $this->output->getVerbosity(),
]);
], $this->consoleFormaterOptions));
}
/**

0 comments on commit e9a2c3d

Please sign in to comment.
You can’t perform that action at this time.