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 24, 2019
1 parent 3895acd commit 17533da
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') && \in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) {
$logger->removeDebugLogger();
}
}
}

2 comments on commit 17533da

@tourze
Copy link
Contributor

@tourze tourze commented on 17533da Nov 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In some case, we should enable DebugLogger in CLI, just like https://packagist.org/packages/runtime/swoole
So, is it better to uncomment this commit ?

@lyrixx
Copy link
Member Author

@lyrixx lyrixx commented on 17533da Nov 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tourze Please open a new issue if something is not good. Thanks

Please sign in to comment.