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

WithMonologChannel on argument instead of the class #475

Open
lyrixx opened this issue Feb 21, 2024 · 1 comment
Open

WithMonologChannel on argument instead of the class #475

lyrixx opened this issue Feb 21, 2024 · 1 comment

Comments

@lyrixx
Copy link
Member

lyrixx commented Feb 21, 2024

Hello,

I was playing with #[WithMonologChannel] attribute. Without reading the doc, I put it on the constructor parameter, because I thought it would work like #[Target], #[Autowire], ... attributes

class HomepageController extends AbstractController
{
    public function __construct(
        #[WithMonologChannel('homepage')]
        private readonly LoggerInterface $logger,
        private readonly MessageBusInterface $bus,
    ) {
    }

But, what a surprise, it didn't work.

Instead it must be set on the class

#[WithMonologChannel('homepage')]
class HomepageController extends AbstractController
{
    public function __construct(
        private readonly LoggerInterface $logger,
        private readonly MessageBusInterface $bus,
    ) {
    }

What about allowing it on the parameter instead ? It feels more natural. And it allows having N different logger

class HomepageController extends AbstractController
{
    public function __construct(
        #[WithMonologChannel('homepage')]
        private readonly LoggerInterface $logger,
        #[WithMonologChannel('billing')]
        private readonly LoggerInterface $billingLogger,
        private readonly MessageBusInterface $bus,
    ) {
    }

WDYT ?

@Seldaek
Copy link
Member

Seldaek commented Feb 22, 2024

Makes sense but it'll require a tweak in monolog I guess.. as that only has target_class

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