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

Symfony autowiring monolog channels #278 #315

Merged
merged 8 commits into from
Sep 2, 2019

Conversation

adrenalinkin
Copy link
Contributor

@adrenalinkin adrenalinkin commented Aug 10, 2019

resolved #278

  • Added possibility for auto-wire monolog channels according to variable type-hint and name.
    Variable will have appropriated name to camel cased monolog channel service name: monolog.logger.acme -> $acmeLogger.
  • Removed useless import DefinitionDecorator.
  • Renamed additional channel in the tests from manualchan to additional

- Added possibility for auto-wire monolog channels according to variable type-hint and name.
  Variable will have appropriated name to camel cased monolog channel service name: `monolog.logger.acme -> $monologLoggerAcme`.
- Removed useless import `DefinitionDecorator`.
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.

👍 LGTM.
Could you add a note in the CHANGELOG?
It will be part of 3.5.0
Thanks

@nicolas-grekas @stof Could you review this one, please?

@adrenalinkin
Copy link
Contributor Author

@lyrixx Thanks. Now information has been add into CHANGELOG.
Should I add some documentation about new feature?

@tristanbes
Copy link
Contributor

I would be interested on how to use that in the README.MD since it adds great DX; (or in the Symfony documentation maybe in the monolog usage ?)

@Seldaek
Copy link
Member

Seldaek commented Aug 16, 2019

Yup more docs on this would be good, if I understand correctly you can only name the variable $monologAcmeLogger for monolog.logger.acme service/acme channel? Any chance of allowing $acmeLogger as well? I feel like the monolog part is kinda superfluous and overly verbose here.

@nicolas-grekas
Copy link
Member

acmeLogger

Would make total sense to support only that.
Could be done by passing $channel.'Logger' as 3rd arg to createAliasForArgument.

A full example would be nice I agree because I'm not sure when this would be useful yet :)

@adrenalinkin
Copy link
Contributor Author

@nicolas-grekas @Seldaek Hello. Just my opinion to clarify this decision.

Current logic is pretty simple. A long time documentation teach us how can we find channel service in the DI container by specific logic monolog.logger.<channel_name>.

When auto-wire has been introduce, anyone who previously solves problem with monolog channel auto-wiring, know, how exactly channel services names generates: acme become to monolog.logger.acme.

So with new feature we are continue this logic - monolog.logger.acme become to Psr\Log\LoggerInterface $monologLoggerAcme.
Furthermore we get stronger protection from naming collision in the projects.

@Seldaek
Copy link
Member

Seldaek commented Aug 16, 2019

IMO naming collision protection isn't needed here as you can only collide with things of class LoggerInterface.. so the monolog name doesn't add anything.

@adrenalinkin
Copy link
Contributor Author

@Seldaek agree, so we can simplify naming according to
monolog.logger.acme -> Psr\Log\LoggerInterface $loggerAcme.

Add the "like" to this comment if this solution acceptable. So I will update code.

About documentation - I am already investigates Symfony Documentation according to all places, where would be good to add information about this new feature.
I will create PR on this holidays.

@Seldaek
Copy link
Member

Seldaek commented Aug 16, 2019

I still find $acmeLogger more readable than $loggerAcme, If you read like a sentence, you would speak of "the acme logger", or "the logger whose name is acme", but not "the logger acme".

The service name convention was different, but it doesn't mean we have to carry that over to the variable name.

@adrenalinkin
Copy link
Contributor Author

@Seldaek I am OK to change as you propose.
We just have different principle of the naming.
I was proposed "logger" first because it common for all variables.
$loggerAcme, $loggerDoctrine, $loggerSecurity etc.
Maybe this approach good only for buisness-code not for reusable.

@Seldaek
Copy link
Member

Seldaek commented Aug 16, 2019

sorry but I don't get your point, I am only suggesting to swap these, i.e. $acmeLogger, $doctrineLogger, $securityLogger.

@adrenalinkin
Copy link
Contributor Author

adrenalinkin commented Aug 16, 2019

@Seldaek no matter, I will change naming as you describe :)

- Updated naming strategy. Channel 'test' become '$testLogger' and etc.
@adrenalinkin
Copy link
Contributor Author

@Seldaek @nicolas-grekas Hello guys! I was finish with this PR and also create PR in symfony docs.
Just notification about it.

adrenalinkin and others added 3 commits August 29, 2019 21:32
- Fixed typo in the `LoggerChannelPass`.
- Added separate test-case for the type-hinted aliases for each logger channel.
@Seldaek Seldaek merged commit fabf119 into symfony:master Sep 2, 2019
@Seldaek
Copy link
Member

Seldaek commented Sep 2, 2019

Thanks

@adrenalinkin adrenalinkin deleted the autowiring_monolog_channels branch September 2, 2019 14:02
javiereguiluz added a commit to javiereguiluz/symfony-docs that referenced this pull request Sep 26, 2019
… monolog channels (adrenalinkin)

This PR was merged into the 4.3 branch.

Discussion
----------

[Monolog] Add documentation about how to autowire monolog channels

resolved: symfony#12195
- Added documentation about how to autowire monolog channels.

Relates to [Symfony autowiring monolog channels](symfony/monolog-bundle#315)

Commits
-------

2e5a627 ISSUE-12195: - Added documentation about how to autowire monolog channels.
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

Successfully merging this pull request may close these issues.

Symfony autowiring monolog channels
6 participants