symfonymonologprocessors

Monolog processors not working with Symfony


I want to use Monolog processors on Symfony, but it looks like monolog doesn't use the processor.

Here is my config_dev.yml relevant extract:

services:
    monolog.formatter.user_info:
        class: Monolog\Formatter\LineFormatter
        arguments:
                - "[%%datetime%%] [%%extra.test%%] %%channel%%.%%level_name%%: %%message%%\n"
    monolog.processor.user_info:
        class: Monolog\Processor\UserInfoProcessor
        tag:
            - { name: monolog.processor }
    monolog.processor.PsrLogMessageProcessor:
        class: Monolog\Processor\PsrLogMessageProcessor
        tag:
            - { name: monolog.processor }

monolog:
    handlers:
        main:
            type:  stream
            path:  %kernel.logs_dir%/%kernel.environment%.log
            level: debug
            formatter: monolog.formatter.user_info

Here is the UserInfoProcessor.php :

namespace Monolog\Processor;

class UserInfoProcessor {

    public function __construct()
    {
        throw new Exception('Test');
        $this->get('logger')->Critical('Here we are');
    }
    public function __invoke(array $record)
    {
        $record['extra']['test'] = "Coucou :D";
        return $record;
    }
}

You can see that I tried a log and an Exception in the constructor, but I have no results, that's why I think Monolog doesn't use the processors. PsrLog doesn't work either.

The formatter works well.

Do you have any suggestion/clue?

Thanks a lot :)


Solution

  • I just wrote "tag" instead of "tags" in the config_dev.yml .. !