Skip to content
Mark Heydon edited this page Oct 15, 2018 · 2 revisions

What is Monolog?

Monolog is an open source library written in PHP that sends your logs to files, sockets, inboxes, databases and various web services. For full details see their homepage at https://seldaek.github.io/monolog/.

What is this project? And what does it have to do with Monolog?

This project is an open source extension (a Monolog Handler to be exact) that allows you to use the Monolog library to send log messages to WP-CLI (The WordPress command line interface). In other words, it can be used when creating your own custom WordPress CLI commands that include logging via Monolog.

Why would I want to log messages using Monolog instead of the WP-CLI logging comments such as WP_CLI::log() method?

One of the great things of Monolog is you can add multiple handlers to output log entries to several places. So for example, if you have a custom WP-CLI command that imports data, using Monolog you could create detailed log entries that will be logged to a file, alerts that get sent to Slack and warnings and errors to the command line all at the same time.

How does the WPCLIHandler work with WP-CLI's --quiet and --debug flags when running custom WP-CLI commands?

The WP-CLI code has its own built-in way of using --debug and --quiet, and WPCLIHandler supports their use. Specifically, if you call something like wp my-command --quiet then only Monolog ERROR level log and above messages will be reported via the command line. Equally calling wp my-command --debug will output DEBUG level log messages along with the WP-CLI debug messages.

Monolog outputs content and extra information with log messages, how can I enable that?

By default, the WP-CLI command line output from this extension does not include the additional context or extra information with the log message. To enable this either pass in 'true' for the '$verbose' parameter in the WPCLIHandler constructor or set WP_DEBUG to true in wp-config.php.