Integrating monolog with WordPress

I’ve been using Simple History for ages, and all in all it’s a really good solution for logging interesting admin activities or even for technical debug information… but also I needed something more abstract and standard for handling more serious events and keeping a better overview of our projects and their integrations.

I looked at some of the alternatives, but they don’t quite hit the developer or user experience I was expecting, so I’m giving it a go with my own attempt at tackling this problem, and as you might have guessed from the title, it’s integrating the de facto standard for logging with PHP: monolog.

This will be a mu-plugin that you will be able to install with composer, and it will provide this features:

  • A $wpdb handler for monolog, that creates a log table using JSON columns for “extra” and “context” columns.
  • A new processor that automatically adds relevant environment information, such as if the request was an ajax or admin request, etc.
  • Compatibility with multi-blog (multi-sites) installations, using a single global table for the logs.
  • A small API to get a minimally preconfigured logger instance.

I think that using JSON columns for “extra” and “context” makes perfect sense given the kind of data that’s expected, and could ease developing new features.

With these features on my roadmap:

  • Integration with the Query Monitor plugin
  • REST and CLI APIs to query logs
  • Admin panel to query logs

Here’s a very rough draft. I hope to get the time to improve it for a more formal release and add proper documentation 🙂