symfonyloggingmonologsymfony3

Monolog not logging context


In my Symfony 3.4. application I have configured a custom logger:

monolog:
  handlers:
    my_channel:
      level: debug
      type: stream
      path: '%kernel.logs_dir%/my_channel.log'
      max_files: 10
      channels: [my_channel]

When I use this logger in my Code which I have injected correctly with the channel "my_channel".

 $this->logger->error('error message', $data = ['my context here']);

On the screen I get $data info correctly shown:

09:00:08 ERROR     [my_channel] error message ["my context here"]

but not in my logs the context is empty:

09:00:08 ERROR     [my_channel] error message []

Question: How can I log the context to my log files too?


Solution

  • The reason was that the context data was not UTF-8 encoded.