PHPackages                             mhcg/monolog-wp-cli - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. mhcg/monolog-wp-cli

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

mhcg/monolog-wp-cli
===================

Extension for Monolog to support outputting to WP-CLI (The WordPress command line interface) when running wp command lines.

v2.2.1(1mo ago)10112.6k↓31.9%3[2 issues](https://github.com/markheydon/monolog-wp-cli/issues)[1 PRs](https://github.com/markheydon/monolog-wp-cli/pulls)1MITPHPPHP ^7.2 || ^8.0CI passing

Since Oct 12Pushed 2w ago2 watchersCompare

[ Source](https://github.com/markheydon/monolog-wp-cli)[ Packagist](https://packagist.org/packages/mhcg/monolog-wp-cli)[ RSS](/packages/mhcg-monolog-wp-cli/feed)WikiDiscussions main Synced yesterday

READMEChangelog (9)Dependencies (13)Versions (17)Used By (1)

Monolog WP-CLI Handler
======================

[](#monolog-wp-cli-handler)

[![Packagist Version](https://camo.githubusercontent.com/52f2fb46ba9cf754e68d90612ce903f78d45b528225a4e279f57a01e75eddbd3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6863672f6d6f6e6f6c6f672d77702d636c692e737667)](https://packagist.org/packages/mhcg/monolog-wp-cli)[![PHP CI](https://github.com/markheydon/monolog-wp-cli/actions/workflows/php.yml/badge.svg?branch=main)](https://github.com/markheydon/monolog-wp-cli/actions/workflows/php.yml)

Extension for [Monolog](https://github.com/Seldaek/monolog) that routes log output through WP-CLI when running `wp` commands.

Installation
------------

[](#installation)

```
composer require mhcg/monolog-wp-cli
```

Requirements
------------

[](#requirements)

- PHP `^7.2 || ^8.0`
- monolog/monolog `^2.5`

Current stable releases target the Monolog 2 line. Monolog 3 support remains planned for a future major release.

Official WordPress-runtime support is maintained separately from the package runtime floor. The current policy supports the current and previous WordPress major series through an explicit smoke-test tuple list rather than a blanket WordPress/PHP cross-product claim.

Usage
-----

[](#usage)

`WPCLIHandler` works like any other Monolog handler. Create the handler and push it onto a logger inside a WP-CLI command context.

By default the handler uses message-only output. Monolog `context` and `extra` data are only rendered when verbose formatting is enabled, either by passing `true` as the third `WPCLIHandler` constructor argument or when `WP_DEBUG` is enabled.

### Version note (v2.2)

[](#version-note-v22)

From v2.2, default `NOTICE` handling changed from `WP_CLI::warning()` to `WP_CLI::log()`.

- Before v2.2: `notice` messages were shown as `Warning:` output.
- From v2.2: `notice` messages are logged as normal output with `(NOTICE)` level prefix.

If you need previous behaviour, pass a custom logger map override as the fourth `WPCLIHandler` constructor argument:

```
$log->pushHandler(
    new WPCLIHandler(
        Logger::INFO,
        true,
        false,
        [
            Logger::NOTICE => [
                'method' => 'warning',
                'includeLevelName' => true,
            ],
        ]
    )
);
```

```
