Skip to content
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

[Monolog] Disable DebugLogger in CLI #30339

Merged
merged 1 commit into from Mar 17, 2019

Conversation

Projects
None yet
5 participants
@lyrixx
Copy link
Member

commented Feb 22, 2019

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
Considering this code:
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();
            }
        }
    }
}

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

@lyrixx lyrixx removed the Bug label Feb 22, 2019

@lyrixx lyrixx force-pushed the lyrixx:monolog-cli branch 2 times, most recently from 98ed852 to bc84107 Feb 22, 2019

@nicolas-grekas nicolas-grekas added this to the next milestone Feb 23, 2019

@nicolas-grekas

This comment has been minimized.

Copy link
Member

commented Feb 23, 2019

Would calling reset() periodically in your worker's main loop work? $logger->reset() or $logger->getDebugLogger()->reset()?

@lyrixx

This comment has been minimized.

Copy link
Member Author

commented Feb 24, 2019

@nicolas-grekas This is another solution but A/ it's not buildin B/ it's useless to have this collector anyway
That's why I prefer this way of doing thing

@lyrixx lyrixx force-pushed the lyrixx:monolog-cli branch from bc84107 to 17533da Feb 24, 2019

@nicolas-grekas

This comment has been minimized.

Copy link
Member

commented Feb 25, 2019

Related to #25876

@lyrixx

This comment has been minimized.

Copy link
Member Author

commented Feb 28, 2019

@nicolas-grekas Let's merge it ?

@lyrixx

This comment has been minimized.

Copy link
Member Author

commented Mar 16, 2019

@stof Are you OK with this one now?

@fabpot

fabpot approved these changes Mar 17, 2019

@fabpot

This comment has been minimized.

Copy link
Member

commented Mar 17, 2019

Thank you @lyrixx.

@fabpot fabpot merged commit 17533da into symfony:master Mar 17, 2019

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
fabbot.io Your code looks good.
Details

fabpot added a commit that referenced this pull request Mar 17, 2019

feature #30339 [Monolog] Disable DebugLogger in CLI (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

@lyrixx lyrixx deleted the lyrixx:monolog-cli branch Mar 17, 2019

@nicolas-grekas nicolas-grekas modified the milestones: next, 4.3 Apr 30, 2019

@fabpot fabpot referenced this pull request May 9, 2019

Merged

Release v4.3.0-BETA1 #31435

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.