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

Channel not used when calling function outside of class #479

Open
baptistebisson opened this issue Apr 18, 2024 · 3 comments
Open

Channel not used when calling function outside of class #479

baptistebisson opened this issue Apr 18, 2024 · 3 comments

Comments

@baptistebisson
Copy link

In my commands, I want loggers to log into the file console.log

Here is my monolog.yaml conf:

when@prod:
    monolog:
        handlers:
            console:
                type: stream
                level: debug
                path: "%kernel.logs_dir%/console.log"
                channels: console
            console-error:
                type: stream
                level: error
                path: "%kernel.logs_dir%/console-error.log"
                channels: console
            info:
                type: stream
                path: "%kernel.logs_dir%/info.log"
                level: info

In my command I've added this: #[WithMonologChannel('console')]

Every log in my command are correctly logged to console.log but every time I call a function outside my command class, the log is logged in info.log.

The issue is that I don't want to add #[WithMonologChannel('console')] in my other class since it's used by other services.

Is there any way to propagate the channel along called functions ?

@lyrixx
Copy link
Member

lyrixx commented Apr 18, 2024

Is there any way to propagate the channel along called functions ?

Nope, this is not how monolog works. What is your use case?
Usually, I add a processor to know what command is used

@baptistebisson
Copy link
Author

Is there any way to propagate the channel along called functions ?

Nope, this is not how monolog works. What is your use case? Usually, I add a processor to know what command is used

I already have a processor to add the command name to the log file. But I want to separate web logs from console logs into two distinct files so it's easier to look at them.
Maybe it's not a common usage.

@lyrixx
Copy link
Member

lyrixx commented Apr 18, 2024

AFAIK, This is not something you can do with monolog out of the box. You can you create your own handler, that does the witch for you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants