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

Skip to content

Commit 17533da

Browse files
committed
[Monolog] Disable DebugLogger in CLI
1 parent 3895acd commit 17533da

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/Symfony/Bridge/Monolog/Logger.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,21 @@ public function reset()
7575
$this->clear();
7676
}
7777

78+
public function removeDebugLogger()
79+
{
80+
foreach ($this->processors as $k => $processor) {
81+
if ($processor instanceof DebugLoggerInterface) {
82+
unset($this->processors[$k]);
83+
}
84+
}
85+
86+
foreach ($this->handlers as $k => $handler) {
87+
if ($handler instanceof DebugLoggerInterface) {
88+
unset($this->handlers[$k]);
89+
}
90+
}
91+
}
92+
7893
/**
7994
* Returns a DebugLoggerInterface instance if one is registered with this logger.
8095
*

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddDebugLogProcessorPass.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ public function process(ContainerBuilder $container)
3030
}
3131

3232
$definition = $container->getDefinition('monolog.logger_prototype');
33+
$definition->setConfigurator([__CLASS__, 'configureLogger']);
3334
$definition->addMethodCall('pushProcessor', [new Reference('debug.log_processor')]);
3435
}
36+
37+
public static function configureLogger($logger)
38+
{
39+
if (method_exists($logger, 'removeDebugLogger') && \in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) {
40+
$logger->removeDebugLogger();
41+
}
42+
}
3543
}

0 commit comments

Comments
 (0)