-
Notifications
You must be signed in to change notification settings - Fork 9.4k
di.xml argument type="array" and Monolog Handlers #2529
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
…ntial processing regardless of array containing indexed numerical keys, or associative string keys in the array. It iterates over the entire array until it finds the $handlerKey that was identified earlier using isHandling(). Once the starting position is found it will execute handle() on each handler unless a handler returns true indicating the handler completed the processing of the record, bubbling to the next handler should not occur, and the loop breaks. This fixes an issue where an associative array of handlers is passed into the Logger constructor when instantiated. magento/magento2#2529 Seldaek#691
Correcting this in Monolog will end up causing a lot of duplicate logging to go to debug.log. There are multiple handlers for every log event, and each handler allows bubbling, the first handler (typically system.log as it is first in the array) and then it will move to the next handler and both will end up writing the same message to their log files. The system handler will write entries for info log level messages and higher, and the debug handler will write for any messages with the debug log level and higher. I haven't tested this but from reading the code I would expect any exceptions to also be duplicated in the debug log because although the system handler checks for exceptions in the contexts array and forwards the records to a different handler in the write() method, the debug handler does not check for this or forward the records anywhere else. |
This looks fixed in Seldaek/monolog#692 |
Yes it's fixed in Monolog in the dev branch (1.17.2 is the latest release on packagist at the moment and doesn't include the fix). Furthermore nothing has been discussed about how to account for this getting patched in Monolog because it will affect how Magento does logging once the patched version is included with Magento. |
@victorgugo Monolog 1.19.0 now includes the Seldaek/monolog#692 fix you mentioned above. Can you re-open this task and create an internal MAGE task to upgrade monolog/monolog to 1.19.0? This is important so that third-party extensions like the ClassyLlama_AvaTax extension can use named handlers. To workaround this issue in Magento/Monolog, we built the ClassyLlama_AvaTax extension to use "0" and "1" as the handler names. This recently caused an issue and someone submitted a pull request to the ClassyLlama_Avatax repository to change this, however this pull request can't be merged until Magento is updated to use the latest version of Monolog: https://github.com/classyllama/ClassyLlama_AvaTax/pull/12/files |
It looks like the specific bug I ran into with the Monolog library was corrected in 1.18.0 release. This issue should be reopened and actually discussed and addressed. The current develop branch of Magento 2 is targeting Monolog 1.16.0. |
Hi @mttjohnson We've created internal ticket MAGETWO-53419 for this issue. |
Currently, Magento uses Monolog 1.22.0 (see https://github.com/magento/magento2/blob/develop/composer.lock#L683). |
@buskamuza, The commit for adjusting the Monolog version is one step and corresponding changes to Magento's use of Monolog also need to be made. The last time I evaluated the Magento\Framework\Logger code in how Magento is setup to utilize monolog, my expectations were that introducing the correction for Monolog would cause duplicate logging of log records cluttering log files with additional noise and space. It doesn't look like the code in that namespace has changed any since. To retain the previous behavior and control which record levels get logged by their respective handlers it may just require an additional I have an example of this type of filtering in a handler ( |
Referencing recent commits related to the inclusion of newer versions of Monolog: It may also be useful to reference other related changes that should get additional attention now that a newer version of Monolog is included: |
Thanks, @mttjohnson . Indeed, logging behavior leads to records duplicate in some cases. |
There is currently a lot of data that gets logged in debug.log, exception.log, and system.log (support_report.log also on EE builds). If everything was in a single file, although it makes more sense from a logging standpoint for consuming everything from a single source, it may have the inadvertent affect of becoming less usable as filtering through all the noise in a single log file would become much more critical in order to get some useful piece of information out of the log. I think the implications of how duplicate log messages is resolved deserves a thorough exploration of how the system handles logging as a whole. The log files have this tendency to grow excessively due to all the data that ends up getting captured in them, and it doesn't seem to be a common practice to manage and rotate logs on a lot of servers further amplifying some of the issues with the usefulness of the logs. I am glad to at least see the mention of logrotate in devdocs though: http://devdocs.magento.com/guides/v2.0/install-gde/install/post-install-config.html#log-rotation As a side note, though related, I found it odd that |
Thanks, @mttjohnson . |
@mttjohnson, thank you for your report. |
Indexing the items in the array as |
I ran into an issue with a 3rd party package (Monolog) that is expecting a numerical array (list) of handlers, but the way they are specified in the di.xml for injecting into the constructor, ObjectManager ends up passing in an array with named keys.
app/etc/di.xml
\Monolog\Logger::addRecord()
Basically the way this is currently behaving is that the array of handlers being passed into Monolog from Magento ends up processing the first handler that it found that
isHandling()
was true for, and fails to process any other handlers after that handler. It takes the key (system
) from the handler in$this->handlers
and tries to increment ($handlerKey++
) the key (systen
) to get the next handler in the list, but that fails.A potential workaround without modifying the Monolog code would be to use a sequential list of numbers on the item names in the di.xml file.
Granted this example seems pointless, but if I'm adding my own custom logger, and multiple handlers it seems to be difficult to specify it the same way as Magento has implemented in the core using di.xml to inject the parameters.
This doesn't seem like a real great solution and doesn't provide a way for additional handlers to be cleanly added to the array. If one extension tried adding a handler item with a name of "2" and some other extension also tried adding their own handler item with a name of "2" that wouldn't work too well.
I'm not seeing any current way that I can specify the list of items for an argument that will just add an item to the array without a named element. If that was an option, it would provide a better workaround for this issue.
Ultimately I would have to blame the poor behavior and limitation on Monolog in how the handlers array is iterated over, and not allowing for the fact that PHP does not distinguish between indexed and associative arrays.
The text was updated successfully, but these errors were encountered: