8000 WithMonologChannel but for property since I have multiple channels · Issue #1960 · Seldaek/monolog · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

WithMonologChannel but for property since I have multiple channels #1960

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

Closed
simPod opened this issue Mar 27, 2025 · 4 comments
Closed

WithMonologChannel but for property since I have multiple channels #1960

simPod opened this issue Mar 27, 2025 · 4 comments
Labels

Comments

@simPod
Copy link
simPod commented Mar 27, 2025

I have a service with multiple channel loggers.

I'd like to use WithMonologChannel attribute to define which logger is for which channel but that attribute currently applies only to the whole class. I'd like to have the ability to use WithMonologChannel like this:

class Foo {
    public function __construct(
        #[WithMonologChannel('foo')]
        LoggerInterface $aaaLogger,
        #[WithMonologChannel('bar')]
        LoggerInterface $bbbLogger
    )
}
@simPod simPod added the Feature label Mar 27, 2025
@micter59
Copy link
micter59 commented Apr 1, 2025

Hello. Maybe you already know, but in the meantime, you can just rename your variables : $fooLogger and $barLogger and you will get the 2 services.

@simPod
Copy link
Author
simPod commented Apr 1, 2025

Yup, I know that. Thanks

@stof
Copy link
Contributor
stof commented Apr 1, 2025

you can use the Target attribute of the DI component to select a specific autowiring alias for an interface (without having to rename the arguments), as supported by Symfony for any interface with multiple autowirable aliases.

The WithMonologChannel attribute maps to autoconfiguring the monolog.logger tag (with the appropriate channel attribute) in MonologBundle, which is a behavior that exists at the level of the definition, not at the level of an argument.
MonologBundle cannot easily add support for using the WithMonologChannel at the argument level (I actually don't see how to implement that without reimplementing a big part of the wiring ourselves, which is definitely not something I want to have to maintain in MonologBundle)

@simPod
Copy link
Author
simPod commented May 6, 2025

Thank you, I'll go with Target attribute, did not know that one.

@simPod simPod closed this as completed May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants
0