how to record in the monolog the result of var_dump ($ _ FILES);

0

I need to save in the monolog the var_dump ($ file) log to identify an error. I do not know how to proceed. My monolog in app \ config

monolog:
    handlers:
        main:
            type: 'rotating_file'
            path: "%kernel.logs_dir%/producao.log"
            level: debug
            channels: [!event]
        console:
            type:   console
            channels: [!event, !doctrine]
    
asked by anonymous 13.07.2016 / 21:54

1 answer

1

If you are inside a controller, just get the logger service and use it to write log to the log file:

$logger = $this->get('logger');
$logger->info(var_dump($var, true));

If you are trying to write a log within a service, you need to inject the logger into it and then use it in the same way as if it were in a controller. Here is an example implementation.

File services.yml :

services:
    app.services.my_service:
        arguments: [ "@logger" ]
        class: AppBundle\Services\MyService

Class AppBundle\Services\MyService :

<?php

namespace AppBundle\Services;

use Psr\Log\LoggerInterface;

class MyService
{
    private $logger;

    public function __construct(LoggerInterface $logger)
    {
        $this->logger = $logger;
    }
}
    
13.07.2016 / 22:14