Skip to content

Monolog WP-CLI Handler

Packagist Version PHP CI

Extension for Monolog that routes log output through WP-CLI when running wp commands.

Install

composer require mhcg/monolog-wp-cli

Requirements

  • PHP ^8.1
  • monolog/monolog ^3.0

The v2.x branch is maintained separately for Monolog 2 users.

Documentation

GuideDescription
First logger in WP-CLIStep-by-step setup for a minimal working logger.
Use WPCLIHandler in a commandIntegrate the handler into an existing command.
WPCLIHandler referenceConstructor, level mapping, and formatter behaviour.
Compatibility policyPackage and WordPress support windows.
FAQsCommon 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' );