We just released Wonolog, a Monolog-based logging package for your WordPress websites. Wonolog is designed to be used by anyone who is interested in what is happening in their websites. So it can also be your WordPress logging library. 🙂

In more and more projects, we felt the need to apply diverse logging strategies. Since there was nothing ready for use in the WordPress universe, we started to develop Wonolog as a dedicated Composer package, and have been using it (also in production) for several months already. Now we want to share it with the world.

What Is Logging?

To have a better understanding of all of the above, let’s go through the individual parts together, one at a time. First up: logging.

The main concept behind logging is the automated creation of logs filled with situation-specific data. The exact way of creating such logs can vary a lot, for example, writing to physical files, sending emails, storing records in various databases, or talking to some external API, to only name a few.

Also, the nature of the data to be logged can be whatever your exact use case may require. In case some external service is not responding, you might want to be informed about just that. If there was some severe error encountered in one of your systems, however, you might also be interested in further information about the concrete incident.

What Is Monolog?

When it comes to logging in the PHP world in general, odds are pretty good that you end up using Monolog.

Adhering to the PSR-3 standard, Monolog is a fully fledged logging library for PHP that comes with all the bells and whistles you can think of. And if not, it is easily extensible. This results in a total number of more than 57 million downloads of Monolog (as of June 1, 2017).

Want to send yourself an email in some arbitrary situation? Not a problem for Monolog. Need notifications about some incidents pop up in a specific Slack channel? Monolog is there for you. Or do you prefer the old school way and log data to a dedicated file? Guess what—Monolog can even handle that. 😉

For more information, please refer to Monolog’s documentation.

Consequently, you might understand that taking Monolog as the foundation to build on was the obvious and natural choice.

So What Is Wonolog, and How Does It Help?

Now that we know a little about logging in general, and also learned about Monolog being the weapon of choice regarding PHP-based logging, all that’s missing is a connection to WordPress. And this is exactly what Wonolog is: a bridge between WordPress (data) and Monolog. This means Wonolog brings virtually anything you might need to perform sophisticated WordPress logging.

Wonolog ships with several ready-made listeners that each target one individual (abstract or concrete) use case in the life of a WordPress request. Say you want to log any failed logins. With Wonolog this is a piece of cake. Would you like to keep track of all WordPress cron requests? Wonolog is here to help. You can even intercept the WordPress-specific exit function, wp_die(), and log any (direct or indirect) usage!

In addition, Wonolog automatically logs PHP core notices, warnings and (fatal) errors, uncaught exceptions (as well as PHP 7+ Throwable), and WordPress core errors such as database errors, HTTP API errors, wp_mail() errors, and 404 errors. Of course, you can customize any of that.

Simply put, Wonolog takes care that your WordPress data gets prepared just like Monolog needs it to be in order to understand and properly process it. Moreover, the package provides both action and filter hooks, and you can configure it via environment variables, which makes Wonolog very flexible, and exposes all the power that Monolog provides.

So How Do I Do WordPress Logging?

First of all, Wonolog requires PHP 5.6 or higher, and it smoothly runs with WordPress 4.6 or higher.

Install via Composer:

$ composer require inpsyde/wonolog

The suggested way to use Wonolog is at the website level.

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. If you want or have to use custom configurations, you have to do this in a MU plugin.

In the simplest scenario, you only have to make sure to include the Composer-generated autoloader before WordPress loads MU plugins, and to create a MU plugin that includes a call to the InpsydeWonologbootstrap(); function. Again, any configuration should also go into this file.

For more information, please refer to Wonolog’s documentation. You may also expect further posts about how exactly we are using Wonolog in various projects.

Why Open Source It?

Just like our fellow WordPress.com VIP service partners, we strongly believe in Open Source. Therefore, we expect nothing less than a positive outcome of open sourcing Wonolog.

We always supported the German WordPress community in any way we can, and also contributed to the development of WordPress itself. Now was the time to give back to the developing part of the WordPress universe, and enable both developers and agencies to make use of Monolog’s unsurpassed functionality—in a WordPress context, and in a comfortable way. And who wouldn’t want to have advanced WordPress logging at their disposal, right?

As usual, we happily accept any kind of feedback over at GitHub, be it issues or feature requests, or provided pull requests.



Happy WordPress logging! 🙂

Comments

  1. Heiko Mamerow1

    Hey, super Danke für dieses tolle Geschenk!

    Und auch noch Danke für diesen wunderbar erklärenden Beitrag. So versteht das wirklich jede/r.

    DANKE!!! 🙂

Leave a reply

Your email address will not be published. Required fields are marked *