If you check the logger interface ( https://github.com/php-fig/log/blob/master/Psr/Log/LoggerInterface.php ), you will see that all logging methods receive a message as a string, so you get warning when trying to log in with a variable type other than a string.
I tried to use the processor to format the array in a custom way, but as expected, the processor starts after sending the variable to the registrar interface.
The dirtiest way to register an array can be any of them of your choice;
$logger->info(json_encode($array)); $logger->info(print_r($array, true)); $logger->info(var_export($array, true));
On the other hand, you can format your array in one processor to centralize the formatting logic using DRY principles.
Json encode array -> Send as Json String -> json decode to array -> format -> json encode again
CustomRequestProcessor.php
<?php namespace Acme\WebBundle; class CustomRequestProcessor { public function __construct() { } public function processRecord(array $record) { try {
Request the query processor in config.yml or services.yml, see node tags for registering the processor for the user channel.
services: monolog.formatter.session_request: class: Monolog\Formatter\LineFormatter arguments: - "[%%datetime%%] %%channel%%.%%level_name%%: %%message%%\n" monolog.processor.session_request: class: Acme\WebBundle\CustomRequestProcessor arguments: [] tags: - { name: monolog.processor, method: processRecord, channel: testchannel }
And in the controller, register your array as a json string,
<?php namespace Acme\WebBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class DefaultController extends Controller { public function indexAction() { $logger = $this->get('monolog.logger.testchannel'); $array = array(3=>"hello" , 1=>"world", 2=>"sf2"); $logger->info(json_encode($array)); return $this->render('AcmeWebBundle:Default:index.html.twig'); } }
Now you can format and register your array as you wish in the central query processor without sorting / forming / walking through the array in each controller.