Skip to content

[Monolog] Disable DebugLogger in CLI #30339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Symfony/Bridge/Monolog/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ public function reset()
$this->clear();
}

public function removeDebugLogger()
Copy link
Contributor

Choose a reason for hiding this comment

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

should be marked as internal

{
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
Original file line number Diff line number Diff line change
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();
}
}
}