Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Monolog] Added a way to configure the ConsoleFormatter from the ConsoleHandler #30345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/Symfony/Bridge/Monolog/Handler/ConsoleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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));
}

/**
Expand Down