Skip to content

Log deprecations on a dedicated Monolog channel #36621

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
May 5, 2020

Conversation

l-vo
Copy link
Contributor

@l-vo l-vo commented Apr 29, 2020

Q A
Branch? master
Bug fix? no
New feature? yes
Deprecations? no
Tickets https://github.com/orgs/symfony/projects/1#card-35233930
License MIT
Doc PR symfony/symfony-docs#13642

This PR allows to activate a specific channel for deprecations.

Base configuration

monolog:
    handlers:
        #...
        deprecation:
            type: stream
            path: "%kernel.logs_dir%/%kernel.environment%.deprecations.log"
        deprecation_filter:
            type: filter
            handler: deprecation
            max_level: info
            channels: ["php"]

Deprecation specific channel enabled:

monolog:
    channels: ['deprecation']
    handlers:
        #...
        deprecation:
            type: stream
            channels: ["deprecation"]
            path: "%kernel.logs_dir%/%kernel.environment%.deprecations.log"

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

LGTM!

I'm wondering: is there a way to make the new channel a kind of alias for the "php" one, so that deprecations follow the same path as the php logs by default?

Note: if this PR is merged, it'll be possible to remove deprecation_filter Monolog handler in the Monolog bundle recipe.

yes! and we could move them to a NullLogger by default for the prod env

@l-vo l-vo force-pushed the use_deprecations_channel branch from 9867d58 to 18200f8 Compare April 30, 2020 20:31
@l-vo
Copy link
Contributor Author

l-vo commented Apr 30, 2020

Do you mean to use the same handler(s) as php channel if no handler if defined for deprecation channel ?
Currently I don't see any way to do that but maybe we could add a fallback (not sure for the name) tag property (with a channel name). FixEmptyLoggerPass could use the handlers defined for this channel instead of NullHandler ?

@nicolas-grekas
Copy link
Member

Do you mean to use the same handler(s) as php channel if no handler if defined for deprecation channel ?

Yes, that's a possibility.

I fear that logging deprecations to a new channel might break apps that configured the php channel and expect deprecations to go there.

Ideally, we'd figure out a way to make the new channel opt-in somehow.

@l-vo
Copy link
Contributor Author

l-vo commented May 4, 2020

Ideally, we'd figure out a way to make the new channel opt-in somehow.

Logging to specific channel is now disabled by default (the service monolog.logger.deprecation doesn't exist). Adding a deprecation additional channel in monolog configuration create the service and enable the feature (see exemple in PR description)

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Nice!
Please consider a doc PR as this will have to be documented appropriately.

@fabpot fabpot force-pushed the use_deprecations_channel branch from fe30f8a to 3d415cb Compare May 5, 2020 05:39
@fabpot
Copy link
Member

fabpot commented May 5, 2020

Thank you @l-vo.

@fabpot fabpot merged commit 55706f7 into symfony:master May 5, 2020
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.1 May 5, 2020
@l-vo l-vo deleted the use_deprecations_channel branch May 5, 2020 08:34
@l-vo
Copy link
Contributor Author

l-vo commented May 5, 2020

PR to documentation added

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