- Issue created by @acbramley
- π¦πΊAustralia dpi Perth, Australia
The main technical challenge would be having different logger instances (channels) autowired per module.
- π¦πΊAustralia dpi Perth, Australia
For those new to autoconfigure, we have an instance in core as of π Enable service autoconfiguration for core event subscribers Fixed
Change record: https://www.drupal.org/node/3357408 β
- π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
kim.pepper β made their first commit to this issueβs fork.
- π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
Had a quick look at this, and it doesn't look like we know which module the services.yml is being loaded from. By the time we get to
CoreServiceProvider
we have a fully merged container definition.This would make it hard to auto configure
file.services.yml
with a logger service idlogger.channel.file
for example.One option is to loop through the service definitions and try to guess a prefix?
- π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
I was looking at
\Drupal\Core\CoreServiceProvider::register()
and adding something like:$container->registerForAutoconfiguration(LoggerAwareInterface::class) ->addMethodCall('setLogger', [new Reference('logger.channel.default')]);
- π¬π§United Kingdom longwave UK
YamlFileLoader::parseDefinitions()
appears to add a_provider
tag to each service with the name of the module.See also #3295542-10: Use logger channel services consistently, instead of the factory object β where I suggested a similar idea.
- π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
Nice!
- Assigned to kim.pepper
- π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
Having a look at this.
- Merge request !5060Adds an autoconfiguration for logger aware services β (Closed) created by kim.pepper
- last update
about 1 year ago 30,422 pass, 2 fail - Status changed to Needs review
about 1 year ago 1:13am 20 October 2023 - π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
Tried an approach of first adding a
logger_aware
tag to any service with a class implementing\Psr\Log\LoggerAwareInterface
by using +$container->registerForAutoconfiguration(LoggerAwareInterface::class) ->addTag('logger_aware');
Then a
\Drupal\Core\DependencyInjection\Compiler\LoggerAwarePass
that looks for those tagged services.Not finding my test service at the moment, so I thought I'd push up what I have to see if others have ideas?
21:03 18:20 Running- π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
Needed to add:
services: _defaults: autoconfigure: true
to
logger_aware_test.services.yml
. - π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
Added a change record.
- last update
about 1 year ago 30,423 pass - π¦πΊAustralia acbramley
Manually tested with services I was playing with before creating this issue and (after applying the other patch to allow autoconfigure) it's working really well. Nice one!
- π¬π§United Kingdom joachim
The CR doesn't mention the 'logger_aware' tag, but the code looks like it's still using it.
- Status changed to Needs work
about 1 year ago 9:40am 20 October 2023 - π¬π§United Kingdom longwave UK
I don't think there are any big issues but just to make sure we considered it: are there BC concerns here where services might have previously implemented LoggerAwareInterface and now we have added behaviour to that? Should we also check that the setLogger() method call isn't already present, just in case?
- π¦πΊAustralia acbramley
Agreed we should probably he checking for existing calls, is it also possible existing class members called $logger could be overwritten? I suppose the interface/trait covers us there.
We should also add a before and after to the CR showing how you no longer need to inject the logger.
- last update
about 1 year ago 30,429 pass - π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
Should we also check that the setLogger() method call isn't already present, just in case?
Sorry, not sure I follow... We are only checking services that implement
LoggerAwareInterface
. ThesetLogger()
method will always be there if they implementLoggerAwareInterface
. - Status changed to Needs review
about 1 year ago 6:41am 22 October 2023 - π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
Updated CR
- last update
about 1 year ago 30,429 pass - last update
about 1 year ago 30,429 pass - π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
Ah I think I follow now.
Should we also check that the setLogger() method call isn't already present, just in case?
Sorry, not sure I follow... We are only checking services that implement
LoggerAwareInterface
. ThesetLogger()
method will always be there if they implementLoggerAwareInterface
.We just need to check if the definition already has a
setLogger
method call defined. - last update
about 1 year ago 30,429 pass - last update
about 1 year ago 30,430 pass - π¬π§United Kingdom longwave UK
I wonder if we should also detect LoggerInterface being used in service constructor arguments (as opposed to a setter method) and automatically create and inject a logger? Or defer that to a followup?
- π¬π§United Kingdom longwave UK
Thinking again we should only do #23 if
autowire: true
is set which probably means we have to wait for π Use autowiring for core modules and services Needs work - Status changed to RTBC
about 1 year ago 5:43pm 23 October 2023 - π¬π§United Kingdom longwave UK
This looks good to me as a self contained issue. I don't think we need to explicitly test that exception, nothing else to do here so this is RTBC.
- last update
about 1 year ago Custom Commands Failed - last update
about 1 year ago Custom Commands Failed - last update
about 1 year ago Custom Commands Failed - Status changed to Needs work
about 1 year ago 2:54am 30 October 2023 - π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
One minor issue with PHPCS
- Status changed to RTBC
about 1 year ago 3:18am 30 October 2023 - π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
Tests green β
-
larowlan β
committed 931ad45c on 10.2.x
Issue #3395032 by kim.pepper, acbramley, longwave: Add autoconfigure for...
-
larowlan β
committed 931ad45c on 10.2.x
-
larowlan β
committed 3d917f37 on 11.x
Issue #3395032 by kim.pepper, acbramley, longwave: Add autoconfigure for...
-
larowlan β
committed 3d917f37 on 11.x
- Status changed to Fixed
about 1 year ago 4:21am 30 October 2023 - π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
Committed to 11.x and backported to 10.2.x
Published CR
Automatically closed - issue fixed for 2 weeks with no activity.