Is there any way to log an entire array using Monolog? I have been reading several docs but didn't find a way to log the entire array in a readable format, any advice?
Docs I've read:
Is there any way to log an entire array using Monolog? I have been reading several docs but didn't find a way to log the entire array in a readable format, any advice?
Docs I've read:
If you check the logger interface (https://github.com/php-fig/log/blob/master/Psr/Log/LoggerInterface.php) you will see all of the logging methods gets message as a string, thus you get a warning when you try to log with a variable type other than string.
I tried to use a processor to format the array in a custom manner, but as expected the processor is triggered after you send the variable to logger interface.
The dirtiest way of logging an array may be any of those for your choice;
On the other hand you may want to format your array in a single proccessor to centralize your formatting logic with DRY principles.
Json encode array -> Send as Json String -> json decode to array -> format -> json encode again
CustomRequestProcessor.php
Register request processor in your config.yml or services.yml, see the tags node for registering the processor for a custom channel.
And in the controller log your array as a json string,
Now you can format and log your array as your desire in a central request processor without sorting/formating/walking on the array in your every controller.