-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Overwriting ObjectManager's $sharedResources leads to strange DI behaviour #3835
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
Comments
It looks like main reason for such behavior is the way how di.xml is merged between stages. But in global configuration of Support Module (Support/etc/di.xml) Support logger is registered. It overrides previous configuration, because arguments defined at later stages of configuration override arguments defined on previous stage of configuration. I can see, that system & debug handlers are already added in etc/di.xml of latest version of Support module. Quick fix for you is to register them in /etc/di.xml of your module. |
Thanks for the quick reply, @antonkril; I'll try your suggestion.
Are you saying that the system and debug handlers are added once again in the Support module, besides the main |
Yes, because global configuration overrides arguments configuration of primary configuration. |
Seems a bit duplicating. |
[TSG-CSL3] For 2.3 (pr18)
Steps to reproduce
developer
mode (don't think it matters though), inject\Psr\Log\LoggerInterface
into any constructor.Expected result
\Psr\Log\LoggerInterface
should produce lines insystem.log
,debug.log
,exception.log
orsupport_report.log
, depending on level etc.Actual result
support_report.log
, including exceptions, layout debug info etc.More info
We've recently upgraded to 2.0.2 and it dawned to me that nothing but a few lines were logged into
system.xml
,exception.log
was empty even though I had one, my debugging logging wasn't working etc.Investigating the problem, I saw that
\Magento\Framework\Logger\Monolog
(thus\Monolog\Logger
) was instantiated 2 times: firstly, with 2 handlers: system and debug (normal handlers), secondly, with only one handler:Magento\Support\Model\Logger\Handler\Report
. I would expect those three handlers to be merged.I originally thought some error had slipped when upgrading, and the ObjectManager got instantiated twice, as when searching for
\Psr\Log\LoggerInterface
, the manager couldn't find it, so it created it again, but this time with the second handler.But that wasn't the case: the manager was instantiated only once. The reason it couldn't find the original logger (with the 2 handlers) was that the
$sharedInstances
was being replaced:magento2/lib/internal/Magento/Framework/App/ObjectManager/Environment/Developer.php
Line 85 in d50ee54
The conclusion is that the original
$sharedInstances
which contains a logger instance is getting replaced with another instance with different handlers.Maybe it's something in our app, but it's worth some investigation, maybe? I also find this a little flaky, as between grabbing the original resources and up until the new ones are loaded, various other instances are created, which will eventually be replaced.
The text was updated successfully, but these errors were encountered: