Monolog log channel

It contains a stack of Handlers and a stack of Processors,
and uses them to store records that are added to it.

CloneableInstantiable
ImplementsMonolog\ResettableInterface
Psr\Log\LoggerInterface
Constants
public Monolog\Logger::ALERT = 550
 

Action must be taken immediately

Example: Entire website down, database unavailable, etc.
This should trigger the SMS alerts and wake you up.

public Monolog\Logger::API = 2
 

Monolog API version

This is only bumped when API breaks are done and should
follow the major version of the library

  • var int
public Monolog\Logger::CRITICAL = 500
 

Critical conditions

Example: Application component unavailable, unexpected exception.

public Monolog\Logger::DEBUG = 100
 

Detailed debug information

public Monolog\Logger::EMERGENCY = 600
 

Urgent alert.

public Monolog\Logger::ERROR = 400
 

Runtime errors

public Monolog\Logger::INFO = 200
 

Interesting events

Examples: User logs in, SQL logs.

public Monolog\Logger::NOTICE = 250
 

Uncommon events

public Monolog\Logger::WARNING = 300
 

Exceptional occurrences that are not errors

Examples: Use of deprecated APIs, poor use of an API,
undesirable things that are not necessarily wrong.

Methods
public __construct(string $name, array $handlers = [], array $processors = [], ?DateTimeZone $timezone = NULL)
 
    public addRecord(int $level, string $message, array $context = []) : bool
     

    Adds a log record.

    • return bool Whether the record has been processed
    public alert( $message, array $context = []) : void
     

    Adds a log record at the ALERT level.

    This method allows for compatibility with common interfaces.

      public close() : void
       

      Ends a log cycle and frees all resources used by handlers.

      Closing a Handler means flushing all buffers and freeing any open resources/handles.
      Handlers that have been closed should be able to accept log records again and re-open
      themselves on demand, but this may not always be possible depending on implementation.

      This is useful at the end of a request and will be called automatically on every handler
      when they get destructed.

      public critical( $message, array $context = []) : void
       

      Adds a log record at the CRITICAL level.

      This method allows for compatibility with common interfaces.

        public debug( $message, array $context = []) : void
         

        Adds a log record at the DEBUG level.

        This method allows for compatibility with common interfaces.

          public emergency( $message, array $context = []) : void
           

          Adds a log record at the EMERGENCY level.

          This method allows for compatibility with common interfaces.

            public error( $message, array $context = []) : void
             

            Adds a log record at the ERROR level.

            This method allows for compatibility with common interfaces.

              public getExceptionHandler() : callable
              public getHandlers() : array
               
              • return HandlerInterface[]
              public static getLevelName(int $level) : string
               

              Gets the name of the logging level.

              public static getLevels() : array
               

              Gets all supported logging levels.

              • return array Assoc array with human-readable level names => level codes.
              public getName() : string
              public getProcessors() : array
               
              • return callable[]
              public getTimezone() : DateTimeZone
               

              Returns the timezone to be used for the timestamp of log records.

              public info( $message, array $context = []) : void
               

              Adds a log record at the INFO level.

              This method allows for compatibility with common interfaces.

                public isHandling(int $level) : bool
                 

                Checks whether the Logger has a handler that listens on the given level

                public log( $level, $message, array $context = []) : void
                 

                Adds a log record at an arbitrary level.

                This method allows for compatibility with common interfaces.

                  public notice( $message, array $context = []) : void
                   

                  Adds a log record at the NOTICE level.

                  This method allows for compatibility with common interfaces.

                    public popHandler() : Monolog\Handler\HandlerInterface
                     

                    Pops a handler from the stack

                    • throws LogicException If empty handler stack
                    public popProcessor() : callable
                     

                    Removes the processor on top of the stack and returns it.

                    • throws LogicException If empty processor stack
                    • return callable
                    public pushHandler(Monolog\Handler\HandlerInterface $handler) : self
                     

                    Pushes a handler on to the stack.

                    public pushProcessor(callable $callback) : self
                     

                    Adds a processor on to the stack.

                    public reset() : void
                     

                    Ends a log cycle and resets all handlers and processors to their initial state.

                    Resetting a Handler or a Processor means flushing/cleaning all buffers, resetting internal
                    state, and getting it back to a state in which it can receive log records again.

                    This is useful in case you want to avoid logs leaking between two requests or jobs when you
                    have a long running process like a worker or an application server serving multiple requests
                    in one process.

                    public setExceptionHandler(?callable $callback) : self
                     

                    Set a custom exception handler that will be called if adding a new record fails

                    The callable will receive an exception object and the record that failed to be logged

                    public setHandlers(array $handlers) : self
                     

                    Set handlers, replacing all existing ones.

                    If a map is passed, keys will be ignored.

                      public setTimezone(DateTimeZone $tz) : self
                       

                      Sets the timezone to be used for the timestamp of log records.

                      public static toMonologLevel( $level) : int
                       

                      Converts PSR-3 levels to Monolog ones if necessary

                      public useMicrosecondTimestamps(bool $micro)
                       

                      Control the use of microsecond resolution timestamps in the 'datetime'
                      member of new records.

                      On PHP7.0, generating microsecond resolution timestamps by calling
                      microtime(true), formatting the result via sprintf() and then parsing
                      the resulting string via \DateTime::createFromFormat() can incur
                      a measurable runtime overhead vs simple usage of DateTime to capture
                      a second resolution timestamp in systems which generate a large number
                      of log events.

                      On PHP7.1 however microseconds are always included by the engine, so
                      this setting can be left alone unless you really want to suppress
                      microseconds in the output.

                        public warning( $message, array $context = []) : void
                         

                        Adds a log record at the WARNING level.

                        This method allows for compatibility with common interfaces.

                          public withName(string $name) : self
                           

                          Return a new cloned instance with the name changed

                          Properties
                          protected $exceptionHandler
                           
                          • var callable|null
                          protected $handlers
                           

                          The handler stack

                          • var HandlerInterface[]
                          protected static $levels = [100 => 'DEBUG', 200 => 'INFO', 250 => 'NOTICE', 300 => 'WARNING', 400 => 'ERROR', 500 => 'CRITICAL', 550 => 'ALERT', 600 => 'EMERGENCY']
                           

                          This is a static variable and not a constant to serve as an extension point for custom levels

                          • var string[] $levels Logging levels with the levels as key
                          protected $microsecondTimestamps
                           
                          • var bool
                          protected $name
                           
                          • var string
                          protected $processors
                           

                          Processors that will process all log records

                          To process records of a single handler instead, add the processor on that specific handler

                          • var callable[]
                          protected $timezone
                           
                          • var DateTimeZone
                          Methods
                          protected handleException(Throwable $e, array $record)
                           

                          Delegates exception management to the custom exception handler,
                          or throws the exception if no custom handler is set.

                          Properties
                          protected static $levels = [100 => 'DEBUG', 200 => 'INFO', 250 => 'NOTICE', 300 => 'WARNING', 400 => 'ERROR', 500 => 'CRITICAL', 550 => 'ALERT', 600 => 'EMERGENCY']
                           

                          This is a static variable and not a constant to serve as an extension point for custom levels

                          • var string[] $levels Logging levels with the levels as key
                          Methods
                          public static getLevelName(int $level) : string
                           

                          Gets the name of the logging level.

                          public static getLevels() : array
                           

                          Gets all supported logging levels.

                          • return array Assoc array with human-readable level names => level codes.
                          public static toMonologLevel( $level) : int
                           

                          Converts PSR-3 levels to Monolog ones if necessary

                          © 2020 Bruce Wells
                          Search Namespaces \ Classes
                          ConfigurationNumbers (0-9.) only