[Monolog] Disable DebugLogger in CLI
This commit is contained in:
parent
3895acd175
commit
17533da49c
@ -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.
|
||||
*
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user