PHPackages                             brianhenryie/bh-wp-cli-logger - 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. brianhenryie/bh-wp-cli-logger

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

brianhenryie/bh-wp-cli-logger
=============================

A PSR logger for WP CLI commands.

v2.0.0(3w ago)029.3k↑151.9%1GPL-2.0-or-laterPHPCI passing

Since Sep 27Pushed 3w ago1 watchersCompare

[ Source](https://github.com/BrianHenryIE/bh-wp-cli-logger)[ Packagist](https://packagist.org/packages/brianhenryie/bh-wp-cli-logger)[ RSS](/packages/brianhenryie-bh-wp-cli-logger/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (43)Versions (4)Used By (1)

[![WordPress tested 6.3](https://camo.githubusercontent.com/478002f831152a0661569c2ab9c3bc1e217d2670a491f8b3fba44169b26d42f1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f576f726450726573732d76362e332532307465737465642d3030373361612e737667)](#) [![PHPCS WPCS](https://camo.githubusercontent.com/504dce428567aedf1d05384c9eac46dcc8a728aa30c7e4c11b8dfc1334883549/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f50485043532d576f72645072657373253230436f64696e672532305374616e64617264732d3838393242462e737667)](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards) [![PHPStan ](https://camo.githubusercontent.com/d25d6512c0f6e84f8a9d94b8ca927a603253e4d67a097778c1563ce05a746699/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c253230382d3261356561372e737667)](https://github.com/szepeviktor/phpstan-wordpress)

WP CLI PSR Logger
=================

[](#wp-cli-psr-logger)

A PSR logger which calls `WP_CLI::line()` with the level name coloured.

Allows easy separation of logic and presentation for CLI commands. I.e. no intermingling of `WP_CLI::line()` in main application code.

Install
-------

[](#install)

```
composer require brianhenryie/bh-wp-cli-logger

```

Operation
---------

[](#operation)

```
$logger = new \BrianHenryIE\WP_CLI_Logger\WP_CLI_Logger();
$logger->warning( 'Something happened!' );
```

[![Something happened screenshot](./.github/something-happened.png "Screenshot of the text Warning: something happened! where the word Warning is yellow")](./.github/something-happened.png)

- It is just a [PSR Logger Interface](https://www.php-fig.org/psr/psr-3/) implementation (aka a PSR-3 logger)
- It does not filter logs to above a certain level
- It does not record the logs anywhere

There is one filter for customising the output:

```
/**
 * Filter logs to control output style.
 *
 * NB: try to use the `context` to only apply this filter to logs output by your own plugin.
 * Return null, an empty array, or an empty message to prevent output.
 *
 * @var ?array{level:string, message:string, context:array, prepend:string, ansi_color:string} $log
 */
$log = apply_filters( 'bh_wp_cli_logger_log', $log );
```

Try it out
----------

[](#try-it-out)

```
composer install
npm install

npx wp-env start

npx wp-env run cli wp cli-logger
```

[![Test plugin screenshot](./.github/bh-wp-cli-logger-test.png "Screenshot of the wp-env output of running the test plugin, showing each standard log level, colorised")](./.github/bh-wp-cli-logger-test.png)

The test plugin CLI command has two options, levels and message:```
NAME

  wp cli-logger

DESCRIPTION

  Test the WP_CLI PSR logger.

SYNOPSIS

  wp cli-logger [...] [--message=]

  [...]
    Optional list of log levels to show.

  [--message=]
    A message to use in the output. Replaces `{level}` in the template if present.
    ---
    default: "This is a {level} log message."
    ---

EXAMPLES

     # Print out a log message for notice
     $ wp test-plugin notice
     Notice:  This is a notice log message.

     # Print out a custom log message for warning
     $ wp test-plugin warning --message="Uh, oh... something looks amiss."
     Warning: Uh, oh... something looks amiss.

     # Print out a log messages for two levels
     $ wp test-plugin notice debug
     Notice:  This is a notice log message.
     Debug:   This is a debug log message.
```

Delete the Docker containers afterwards:

```
npx wp-env destroy
```

Rationale
---------

[](#rationale)

Error: red, warning: yellow, and notice: blue are the standard WordPress `admin_notice` colours.

Debug: blue is the standard WP\_CLI debug colour.

Emergency, alert and critical use `WP_CLI::error_multi_line()`.

Info logs are not prepended with "Info: ", as other levels are. I'm not 100% set on this.

TODO
----

[](#todo)

### Level Filtering

[](#level-filtering)

I imagine there is a Composer package that provides the same utility as WooCommerce's [WC\_Logger::should\_handle()](https://github.com/woocommerce/woocommerce/blob/fe8f3bb8195dea8c0f7e544a57df0d985d2dfc52/plugins/woocommerce/includes/class-wc-logger.php#L82-L93) function, and is extensible. If I come across one, I'll include it here.

When WP CLI commands are appended with `--debug` or more specifically `--debug=my-plugin-slug`, all messages *should* be output. This should be part of any `::should_handle()` function.

### Context

[](#context)

Context is not printed.

See Also
--------

[](#see-also)

- [BH WP Logger](https://github.com/BrianHenryIE/bh-wp-logger) – this class was extracted from that
- [BH Color Logger](https://github.com/BrianHenryIE/bh-color-logger) – like this, for unit tests

###  Health Score

48

—

FairBetter than 93% of packages

Maintenance95

Actively maintained with recent releases

Popularity28

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~989 days

Total

2

Last Release

22d ago

Major Versions

v1.0.0 → v2.0.02026-06-13

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4720401?v=4)[Brian Henry](/maintainers/BrianHenryIE)[@BrianHenryIE](https://github.com/BrianHenryIE)

---

Top Contributors

[![BrianHenryIE](https://avatars.githubusercontent.com/u/4720401?v=4)](https://github.com/BrianHenryIE "BrianHenryIE (29 commits)")

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/brianhenryie-bh-wp-cli-logger/health.svg)

```
[![Health](https://phpackages.com/badges/brianhenryie-bh-wp-cli-logger/health.svg)](https://phpackages.com/packages/brianhenryie-bh-wp-cli-logger)
```

###  Alternatives

[sentry/sentry

PHP SDK for Sentry (http://sentry.io)

1.9k247.1M335](/packages/sentry-sentry)[symfony/cache

Provides extended PSR-6, PSR-16 (and tags) implementations

4.2k373.5M3.3k](/packages/symfony-cache)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[illuminate/log

The Illuminate Log package.

6225.3M623](/packages/illuminate-log)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[api-platform/metadata

API Resource-oriented metadata attributes and factories

275.0M219](/packages/api-platform-metadata)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
