Skip to content

Latest commit

 

History

History
59 lines (35 loc) · 2.8 KB

04-hook-listeners.md

File metadata and controls

59 lines (35 loc) · 2.8 KB

Hook listeners

Table of Contents

Introducing Hook Listeners

When Wonolog is bootstrapped without any further configuration, it starts logging some events that happen in the WordPress website.

Some of these events might be PHP errors, while others might be events specific to WordPress.

The way Wonolog does it is not rocket science: it adds some callbacks to actions and filters triggered by WordPress and according to the hook fired and the arguments associated with it, some log records may be added.

This task is done by specialized objects called hook listeners.

Technically speaking, a hook listener is an object implementing Inpsyde\Wonolog\HookListener\HookListenerInterface.

Conceptually, a hook listener is an object that "listens to" one or more hooks triggered and based on some internal logic, and returns an object implementing LogDataInterface (see Log record data as Wonolog objects).

When this happens, the returned object gets logged.

Wonolog Hook Listeners

Wonolog ships with a few hook listeners used to log events that happen in WordPress.

All of these are in the Inpsyde\Wonolog\HookListener namespace, and they are:

  • CronDebugListener
  • DbErrorListener
  • FailedLoginListener
  • HttpApiListener
  • MailerListener
  • QueryErrorsListener
  • WpDieHandlerListener

Every listener is specialized in producing logs for a specific WordPress core "area", or API.

Of course, it is possible to write custom hook listeners, and actually that's the suggested way to log records using Wonolog without explicitly coupling your code to it.

Refer to Wonolog Customization to learn how to disable some or all of the shipped listeners, and to Custom Hook Listeners to have a look at a complete implementation of a custom hook listener and its integration with Wonolog.


Read next:

  • 05 - Wonolog Customization for a deep travel through all the possible configurations available for any aspect of the package.
  • 06 - Custom Hook Listeners to see a complete example of a custom hook listener, its integration in Wonolog, and all the things that you need to know in order to write reusable Wonolog extensions.

Read previous:


< Back to Index