Symfony5 / Monolog

config/services.yaml

  •   # Show request info in log (URL, IP, referer, etc)
      monolog.processor.web:
        class: Monolog\Processor\WebProcessor
        tags:
          - { name: monolog.processor }
    
      # Include stack traces
      monolog.formatter.line:
        class: Monolog\Formatter\LineFormatter
        calls:
          - [includeStacktraces]

config/packages/prod/monolog.yaml

  • monolog:
      handlers:
        # log rotation: https://symfony.com/doc/current/logging.html#how-to-rotate-your-log-files
        # mailing:      https://symfony.com/doc/current/logging/monolog_email.html
        # levels:       https://stackify.com/php-monolog-tutorial/
        main:
          # if *one* log entry is error or higher, pass *all* to file_log
          type: fingers_crossed
          #action_level: warning
          action_level: error
          # practically silences the log
          #action_level: alert
          excluded_http_codes: [404, 405]
          buffer_size: 100 # How many messages should be saved? Prevent memory leaks
          handler: grouped
          # That does not eliminate deprecation warnings
          #channels: [ "!deprecation" ]
        grouped:
          type: group
          #            members: [file_log, deduplicated]
          members: [file_log]
        file_log:
          #type: stream
          type:  rotating_file
          # max number of log files to keep
          # defaults to zero, which means infinite files
          max_files: 14
          #path: php://stderr
          path: "%kernel.logs_dir%/%kernel.environment%.log"
          #level: debug
          #level: warning
          level: error
          # practically silences the log
          #level: alert
          #formatter: monolog.formatter.json
          formatter: monolog.formatter.line
        #        deduplicated:
        #            type: deduplication
        #            handler: symfony_mailer
        #        symfony_mailer:
        #            type:         symfony_mailer
        #            from_email:   'log-errors@example.com'
        #            to_email:     'me@example.com'
        #            subject:      'An Error Occurred! %%message%%'
        #            level:        debug
        #            formatter:    monolog.formatter.html
        #            content_type: text/html
    
        #        phperrorlog:
        #            type: stream
        #            path: php://stderr
        #            level: notice
        console:
          type: console
          process_psr_3_messages: false
          channels: ["!event", "!doctrine"]