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

Skip to content

[Monolog] Really reset logger when calling logger::reset() #30410

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 5, 2019

Conversation

lyrixx
Copy link
Member

@lyrixx lyrixx commented Feb 28, 2019

Q A
Branch? 4.2
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

@lyrixx
Copy link
Member Author

lyrixx commented Feb 28, 2019

looks like Fabbot is broken.

Anyway, this patch is much better, because it actually does the work. BTW, introducing the method reset() without calling the parent was a BC break, isn't ?

But it is still not perfect. ATM we rely on the fact that processors and handlers are shared among all loggers. But there is one logger per channel. So when we call Logger::reset(), we call it on only one logger. Not all!

Let me explain this a bit more. Let's consider this config:

monolog:
    handlers:
        main:
            type: fingers_crossed
            action_level: error
            handler: buffer
            buffer_size: 50
            channels: ["!php"]
        buffer:
            type: buffer
            handler: file
        file:
            type: stream
            path: '%kernel.logs_dir%/%kernel.environment%.log'

        php:
            type: fingers_crossed
            action_level: error
            handler: php_file
            buffer_size: 50
            channels: ["php"]
        php_file:
            type: stream
            path: '%kernel.logs_dir%/%kernel.environment%-php.log'

And with this PHP script:

<?php

require __DIR__.'/vendor/autoload.php';

$k = new AppKernel('dev', true);
$k->boot();
$c = $k->getContainer();

// (I had to patch SF to make theses services public)
$c->get('monolog.logger.php')->debug('debug from php - XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
$c->get('monolog.logger.consumer')->debug('debug from consumer - YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY');
$c->get('monolog.logger.consumer')->reset();


dump([
    'logger php' => $c->get('monolog.logger.php'),
    'logger consumer' => $c->get('monolog.logger.consumer')
]);

We can simulate our issue. In my consumer, I got monolog.logger.consumer logger. And when I call reset() it's well reset. But the monolog.logger.php is not reset :/

In my application, I don't have this issue because our configuration is more classical. But I know some people are doing this kind of configuration. We need to know that :)

@fabpot
Copy link
Member

fabpot commented Mar 4, 2019

Isn't it something we can do on 3.4?

@lyrixx
Copy link
Member Author

lyrixx commented Mar 5, 2019

@fabpot The Logger::reset() did not exist in 3.4. So I guess it's not possible as it would be a new feature. on 4.2 it's a bug fix.

@fabpot
Copy link
Member

fabpot commented Mar 5, 2019

Thank you @lyrixx.

@fabpot fabpot merged commit 08a20ee into symfony:4.2 Mar 5, 2019
fabpot added a commit that referenced this pull request Mar 5, 2019
… (lyrixx)

This PR was merged into the 4.2 branch.

Discussion
----------

[Monolog] Really reset logger when calling logger::reset()

| Q             | A
| ------------- | ---
| Branch?       | 4.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Commits
-------

08a20ee [Monolog] Really reset logger when calling logger::reset()
@lyrixx lyrixx deleted the logger-reset branch March 5, 2019 09:46
@fabpot fabpot mentioned this pull request Apr 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants