how to write the output of var_dump($_FILES) to monolog;

Asked

Viewed 227 times

0

I need to save the var_dump($file) records in the monolog to identify an error. I don’t 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]
  • If you want to record the exit of var_dump(), use the function var_export() ex: $resultado = var_export($var, true);

  • And you can put that to work on the monolog?

1 answer

1


If you’re inside a controller, just pick up the service logger and use it to record log in the log file:

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

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

Filing cabinet 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;
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.