monolog-bundle
monolog-bundle copied to clipboard
WithMonologChannel on argument instead of the class
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 ?