Skip to content

Latest commit

 

History

History
169 lines (148 loc) · 14.5 KB

02-handlers-formatters-processors.md

File metadata and controls

169 lines (148 loc) · 14.5 KB

Handlers, Formatters and Processors

Handlers

Log to files and syslog

Send alerts and emails

Log specific servers and networked logging

Logging in development

Log to databases

Wrappers / Special Handlers

  • FingersCrossedHandler: A very interesting wrapper. It takes a logger as parameter and will accumulate log records of all levels until a record exceeds the defined severity level. At which point it delivers all records, including those of lower severity, to the handler it wraps. This means that until an error actually happens you will not see anything in your logs, but when it happens you will have the full information, including debug and info records. This provides you with all the information you need, but only when you need it.
  • DeduplicationHandler: Useful if you are sending notifications or emails when critical errors occur. It takes a logger as parameter and will accumulate log records of all levels until the end of the request (or flush() is called). At that point it delivers all records to the handler it wraps, but only if the records are unique over a given time period (60seconds by default). If the records are duplicates they are simply discarded. The main use of this is in case of critical failure like if your database is unreachable for example all your requests will fail and that can result in a lot of notifications being sent. Adding this handler reduces the amount of notifications to a manageable level.
  • WhatFailureGroupHandler: This handler extends the GroupHandler ignoring exceptions raised by each child handler. This allows you to ignore issues where a remote tcp connection may have died but you do not want your entire application to crash and may wish to continue to log to other handlers.
  • BufferHandler: This handler will buffer all the log records it receives until close() is called at which point it will call handleBatch() on the handler it wraps with all the log messages at once. This is very useful to send an email with all records at once for example instead of having one mail for every log record.
  • GroupHandler: This handler groups other handlers. Every record received is sent to all the handlers it is configured with.
  • FilterHandler: This handler only lets records of the given levels through to the wrapped handler.
  • SamplingHandler: Wraps around another handler and lets you sample records if you only want to store some of them.
  • NoopHandler: This handler handles anything by doing nothing. It does not stop processing the rest of the stack. This can be used for testing, or to disable a handler when overriding a configuration.
  • NullHandler: Any record it can handle will be thrown away. This can be used to put on top of an existing handler stack to disable it temporarily.
  • PsrHandler: Can be used to forward log records to an existing PSR-3 logger
  • TestHandler: Used for testing, it records everything that is sent to it and has accessors to read out the information.
  • HandlerWrapper: A simple handler wrapper you can inherit from to create your own wrappers easily.

Formatters

  • LineFormatter: Formats a log record into a one-line string.
  • HtmlFormatter: Used to format log records into a human readable html table, mainly suitable for emails.
  • NormalizerFormatter: Normalizes objects/resources down to strings so a record can easily be serialized/encoded.
  • ScalarFormatter: Used to format log records into an associative array of scalar values.
  • JsonFormatter: Encodes a log record into json.
  • WildfireFormatter: Used to format log records into the Wildfire/FirePHP protocol, only useful for the FirePHPHandler.
  • ChromePHPFormatter: Used to format log records into the ChromePHP format, only useful for the ChromePHPHandler.
  • GelfMessageFormatter: Used to format log records into Gelf message instances, only useful for the GelfHandler.
  • LogstashFormatter: Used to format log records into logstash event json, useful for any handler listed under inputs here.
  • ElasticaFormatter: Used to format log records into an Elastica\Document object, only useful for the ElasticSearchHandler.
  • LogglyFormatter: Used to format log records into Loggly messages, only useful for the LogglyHandler.
  • FlowdockFormatter: Used to format log records into Flowdock messages, only useful for the FlowdockHandler.
  • MongoDBFormatter: Converts \DateTime instances to \MongoDate and objects recursively to arrays, only useful with the MongoDBHandler.
  • LogmaticFormatter: User to format log records to Logmatic messages, only useful for the LogmaticHandler.

Processors

Third Party Packages

Third party handlers, formatters and processors are listed in the wiki. You can also add your own there if you publish one.

Usage | Utility classes