[Monolog] Disable DebugLogger in CLI

This commit is contained in:
Grégoire Pineau 2019-02-22 11:16:14 +01:00
parent 3895acd175
commit 17533da49c
2 changed files with 23 additions and 0 deletions

View File

@ -75,6 +75,21 @@ class Logger extends BaseLogger implements DebugLoggerInterface, ResetInterface
$this->clear();
}
public function removeDebugLogger()
{
foreach ($this->processors as $k => $processor) {
if ($processor instanceof DebugLoggerInterface) {
unset($this->processors[$k]);
}
}
foreach ($this->handlers as $k => $handler) {
if ($handler instanceof DebugLoggerInterface) {
unset($this->handlers[$k]);
}
}
}
/**
* Returns a DebugLoggerInterface instance if one is registered with this logger.
*

View File

@ -30,6 +30,14 @@ class AddDebugLogProcessorPass implements CompilerPassInterface
}
$definition = $container->getDefinition('monolog.logger_prototype');
$definition->setConfigurator([__CLASS__, 'configureLogger']);
$definition->addMethodCall('pushProcessor', [new Reference('debug.log_processor')]);
}
public static function configureLogger($logger)
{
if (method_exists($logger, 'removeDebugLogger') && \in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) {
$logger->removeDebugLogger();
}
}
}