Wonolog
Monolog-based logging package for WordPress.
Table of Contents
- Introduction
- Minimum Requirements and Dependencies
- Getting Started
- Wonolog Defaults
- Learn More
- License and Copyright
Introduction
Wonolog is a Composer package (not a plugin) that allows to log anything that happens in a WordPress site.
It is based on Monolog, which, with its over 38 millions of downloads and thousands of dependent packages, is the most popular logging library for PHP, compatible with the PSR-3 standard.
Minimum Requirements and Dependencies
Wonolog requires:
- PHP 5.6+
- WordPress 4.6+
Via Composer, Wonolog requires monolog/monolog
(MIT).
When installed for development, via Composer, Wonolog also requires:
phpunit/phpunit
(BSD-3-Clause)brain/monkey
(MIT)mikey179/vfsStream
(BSD-3-Clause)
Getting Started
Wonolog should be installed via Composer.
Its package name is inpsyde/wonolog
.
The suggested way to use Wonolog is at website level.
If you don't use Composer to manage your whole website then Wonolog is probably not for you. You might be able to use it anyway, but support is not guaranteed.
It's easily possible to develop plugins and themes compatible with Wonolog logging even without explicitly declaring it as a dependency.
A couple of noteworthy things:
- all Wonolog configurations have to be done in a MU plugin;
- in a WordPress multisite installation, all Wonolog configurations are naturally site-wide.
On the bright side, Wonolog comes with a super easy bootstrap routine and some out-of-the-box configurations that make it possible to have a working and effective logging system with zero effort.
To get started with defaults settings, this is required:
- install Wonolog via Composer;
- ensure Composer autoload is loaded in
wp-config.php
or anytime before the'muplugins_loaded'
action is fired; - create a MU plugin that, at least, contains this code:
<?php
Inpsyde\Wonolog\bootstrap();
Wonolog Defaults
The three steps described above are all that is necessary to have a working logging system that uses Monolog to write logs in a file. The path of that file changes based on current date, using the following format:
{WP_CONTENT_DIR}/wonolog/{Y/m/d}.log
,
with {Y/m/d}
being replaced by date( 'Y/m/d' )
.
For example, a target file could be /wp-content/2017/02/27.log
.
What is actually logged depends on the value of WP_DEBUG_LOG
constant.
When WP_DEBUG_LOG
is set to true
, Wonolog will log everything.
When WP_DEBUG_LOG
is set to false
, Wonolog will only log events with a log level higher or equal to ERROR
, according to PSR-3 log levels.
"Automatically" logged events include:
- PHP core notices, warnings and (fatal) errors;
- uncaught exceptions;
- WordPress errors and events (e.g., DB errors, HTTP API errors,
wp_mail()
errors, and 404 errors).
This is just the default behavior.
The bootstrap()
function provides entry points for many configurations and customizations.
Moreover, the package provides both action and filter hooks, and can be configured via environment variables, which makes Wonolog very flexible, and exposes all the power that Monolog provides.
Learn More
Documentation of Wonolog features, defaults, configuration and ways to extends it can be found in separate files:
- 01 - Monolog Primer to learn a bit more about Monolog core concepts.
- 02 - Basic Wonolog Concepts to learn the basics of logging with Wonolog.
- 03 - A Deeper Look at Wonolog to learn more advanced concepts and features of Wonolog.
- 04 - Hook Listeners to read about hook listeners, the powerful feature of Wonolog that allows for logging any WordPress code.
- 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.
License and Copyright
Copyright (c) 2017 Inpsyde GmbH.
Wonolog code is licensed under MIT license.
The team at Inpsyde is engineering the Web since 2006.