-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Conversation
98ed852
to
bc84107
Compare
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddDebugLogProcessorPass.php
Outdated
Show resolved
Hide resolved
Would calling reset() periodically in your worker's main loop work? |
@nicolas-grekas This is another solution but A/ it's not buildin B/ it's useless to have this collector anyway |
Related to #25876 |
@nicolas-grekas Let's merge it ? |
@stof Are you OK with this one now? |
Thank you @lyrixx. |
This PR was merged into the 4.3-dev branch. Discussion ---------- [Monolog] Disable DebugLogger in CLI | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | | Fixed tickets | #30333 symfony/monolog-bundle#165 #25876 | License | MIT | Doc PR | <details> <summary>Considering this code:</summary> ```php namespace App\Command; use Psr\Log\LoggerInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class LeakCommand extends Command { protected static $defaultName = 'leak'; private $logger; public function __construct(LoggerInterface $logger) { $this->logger = $logger; parent::__construct(); } protected function execute(InputInterface $input, OutputInterface $output) { $reportedAt = time(); while (true) { $this->logger->info('Hello'); if (time() - $reportedAt >= 1) { $output->writeln(sprintf('%dMb', memory_get_usage() / 1024 / 1024)); $reportedAt = time(); } } } } ``` </details> Without the patch ``` >…/dev/labs/symfony/website-skeleton(monolog %) bin/console leak 7Mb 28Mb 51Mb 76Mb 97Mb ```` With the patch ``` >…/dev/labs/symfony/website-skeleton(monolog %) bin/console leak 6Mb 6Mb 6Mb 6Mb ``` Commits ------- 17533da [Monolog] Disable DebugLogger in CLI
…atcher' service (lyrixx) This PR was submitted for the 4.4 branch but it was merged into the 3.4 branch instead (closes #32421). Discussion ---------- [EventDispatcher] Add tag kernel.rest on 'debug.event_dispatcher' service | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | In CLI, Symfony leaks because it uses the TraceableEventDispatcher. Let's make this service resetable. This PR is related to #32418 --- Side note: Forcing user to use the `ServicesResetter` is IMHO bad for the DX. I prefer to have something that does not leak by default. More over, the TraceableEventDispatcher stores some informations for the profiler. But in CLI it does not make sens, since the tooling does not exist. I have already fixed such issue for monolog in #30339. I think we should do the same for the TraceableEventDispatcher. --- Note: When using #32418 + this PR and with the following code, it does not leak **at all** <details> <summary>code</summary> ```php <?php namespace App\Command; use Psr\Log\LoggerInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\EventDispatcher\Event; use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; class LeakCommand extends Command { protected static $defaultName = 'leak'; private $dispatcher; private $resetter; private $logger; public function __construct(EventDispatcherInterface $dispatcher, ServicesResetter $resetter, LoggerInterface $logger) { $this->dispatcher = $dispatcher; $this->resetter = $resetter; $this->logger = $logger; parent::__construct(); } protected function execute(InputInterface $input, OutputInterface $output) { $this->dispatcher->addListener(MyEvent::class, function ($e) { }); for ($i=0; $i < INF; $i++) { $output->writeln(memory_get_usage()); $this->dispatcher->dispatch(new MyEvent()); $this->logger->debug('some log'); // if ($i > 2000) { // meminfo_dump(fopen('/tmp/my_dump_file.json', 'w')); // die; // } usleep(100); $this->resetter->reset(); } } } class MyEvent {} ``` </detail> Commits ------- 5249eaf [EventDispatcher] Add tag kernel.rest on 'debug.event_dispatcher' service
@@ -75,6 +75,21 @@ public function reset() | |||
$this->clear(); | |||
} | |||
|
|||
public function removeDebugLogger() |
There was a problem hiding this comment.
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
Considering this code:
Without the patch
With the patch