How to Define a Custom Logging Formatter

Version: 2.8
Edit this page

Warning: You are browsing the documentation for Symfony 2.8, which is no longer maintained.

Read the updated version of this page for Symfony 5.3 (the current stable version).

How to Define a Custom Logging Formatter

Each logging handler uses a Formatter to format the record before logging it. All Monolog handlers use an instance of Monolog\Formatter\LineFormatter by default but you can replace it easily. Your formatter must implement Monolog\Formatter\FormatterInterface.

  • YAML
  • XML
  • PHP
1
2
3
4
5
6
7
8
9
10
# app/config/config.yml
services:
    my_formatter:
        class: Monolog\Formatter\JsonFormatter
monolog:
    handlers:
        file:
            type: stream
            level: debug
            formatter: my_formatter
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.