Skip to content

Commit

Permalink
[Monolog] Disable DebugLogger in CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
lyrixx committed Feb 22, 2019
1 parent fec0475 commit bc84107
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Symfony/Bridge/Monolog/Logger.php
Expand Up @@ -75,6 +75,21 @@ public function reset()
$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.
*
Expand Down
Expand Up @@ -30,6 +30,14 @@ public function process(ContainerBuilder $container)
}

$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') && 'cli' === \PHP_SAPI) {
$logger->removeDebugLogger();
}
}
}

0 comments on commit bc84107

Please sign in to comment.