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

Add support for the #[WithMonologChannel] attribute of Monolog 3.5 to autoconfigure the channel #468

Merged
merged 1 commit into from
Oct 28, 2023

Conversation

stof
Copy link
Member

@stof stof commented Oct 24, 2023

Configuring custom channels on some services is one of the last reasons I have for defining services explicitly in my config files. This attribute allows to solve that.

use Monolog\Attribute\WithMonologChannel;
use Psr\Log\LoggerInterface;

#[WithMonologChannel('fixture')]
class ServiceWithChannel
{
    public function __construct(private LoggerInterface $logger) {}
}

@OskarStark OskarStark changed the title Add the WithLoggerChannel attribute to autoconfigure the channel Add the #[WithLoggerChannel] attribute to autoconfigure the channel Oct 24, 2023
/**
* @readonly
*/
public string $channel;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public string $channel;
public $channel;

Copy link
Member Author

Choose a reason for hiding this comment

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

IMO, it is fine to keep the typed property there. Attributes don't work on PHP 7.2 anyway

Copy link
Member

Choose a reason for hiding this comment

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

why not using CPP then?

Copy link
Member Author

Choose a reason for hiding this comment

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

ah indeed. For some reasons, I thought CPP was 8.1 like the readonly properties.

Copy link
Member

@lyrixx lyrixx left a comment

Choose a reason for hiding this comment

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

👍🏼 I like it

@derrabus
Copy link
Member

Can we please write tests for that? And should we move the attribute to the bridge?

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Oct 24, 2023

should we move the attribute to the bridge?

Or better: to monolog itself?

We already have https://github.com/Seldaek/monolog/blob/main/src/Monolog/Attribute/AsMonologProcessor.php

@stof
Copy link
Member Author

stof commented Oct 24, 2023

@Seldaek do you think this attribute should go in Monolog itself ?

@stof
Copy link
Member Author

stof commented Oct 24, 2023

I submitted it to Monolog in Seldaek/monolog#1847
If this is accepted, I will update this PR to use the Monolog attribute instead.

@stof stof changed the title Add the #[WithLoggerChannel] attribute to autoconfigure the channel Add support for the #[WithMonologChannel] attribute of Monolog 3.5 to autoconfigure the channel Oct 26, 2023
@stof stof merged commit b98138a into symfony:master Oct 28, 2023
11 checks passed
@stof stof deleted the channel_attribute branch October 28, 2023 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants