Monolog WP-CLI Handler
Extension for Monolog that routes log output through WP-CLI when running wp commands.
Install
composer require mhcg/monolog-wp-cliRequirements
- PHP
^8.1 - monolog/monolog
^3.0
The v2.x branch is maintained separately for Monolog 2 users.
Documentation
| Guide | Description |
|---|---|
| First logger in WP-CLI | Step-by-step setup for a minimal working logger. |
| Use WPCLIHandler in a command | Integrate the handler into an existing command. |
| WPCLIHandler reference | Constructor, level mapping, and formatter behaviour. |
| Compatibility policy | Package and WordPress support windows. |
| FAQs | Common questions about Monolog, WP-CLI, and this package. |
Quick example
<?php
use Monolog\Level;
use Monolog\Logger;
use MHCG\Monolog\Handler\WPCLIHandler;
$log = new Logger( 'mycommand' );
$log->pushHandler( new WPCLIHandler( Level::Info ) );
$log->info( 'Started running' );
$log->warning( 'Something happened of note' );
$log->error( 'An error has occurred' );