Monolog

Monolog #

Based on PSR3

Verbosity #

SHELL_VERBOSITY value Minimum log level
-1 ERROR
1 NOTICE
2 INFO
3 DEBUG

Storage #

Handlers: Writing Logs to different Locations #

Instead of writing log files somewhere, some handlers are used to filter or modify log entries before sending them to other handlers.

  • Fingers crossed :

    • stores all log messages during a request but only passes them to a second handler if one of the messages reaches an action_level
    • allows you to set a minimum log threshold, no logs will be written unless a log of the given threshold or higher has been given. This assumes you only want all your logs if an errors occurs at which point you’ll want to know as much as you can
    • used by default in production
    monolog:
      handlers:
          filter_for_errors:
              type: fingers_crossed
              # if *one* log is error or higher, pass *all* to file_log
              action_level: error
              handler: file_log
    
          # now passed *all* logs, but only if one log is error or higher
          file_log:
              type: stream
              path: "%kernel.logs_dir%/%kernel.environment%.log"
    
          # still passed *all* logs, and still only logs error or higher
          syslog_handler:
              type: syslog
              level: error
    
  • Rotating file:

    • Creates a new log file every day and can also remove old files automatically
monolog:
    handlers:
        main:
            type:  rotating_file
            path:  '%kernel.logs_dir%/%kernel.environment%.log'
            level: debug
            # max number of log files to keep
            # defaults to zero, which means infinite files
            max_files: 10