-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
Steps to reproduce
- M2 2.0.2
- In
developermode (don't think it matters though), inject\Psr\Log\LoggerInterfaceinto any constructor.
Expected result
- Logging using
\Psr\Log\LoggerInterfaceshould produce lines insystem.log,debug.log,exception.logorsupport_report.log, depending on level etc.
Actual result
- Everything gets logged into
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
| $sharedInstances = $originalSharedInstances; |
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.