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.

v1.0.0(2y ago)021.6k↓50%1GPL-2.0-or-laterPHP

Since Sep 27Pushed 2y 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 1mo ago

READMEChangelogDependencies (29)Versions (2)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.

### psr/log &gt;=2.0

[](#psrlog-20)

This currently requires `"psr/log": "^1.0"`. [v2.0](https://github.com/php-fig/log/compare/1.1.4...2.0.0) requires PHP 8.0 and introduces parameter types; [3.0](https://github.com/php-fig/log/compare/2.0.0...3.0.0) then introduces return types.

### 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

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity43

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

Unknown

Total

1

Last Release

964d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3541a510f89dedd04f0e7103201e411f6f22685a13e941b3384d97d4c7d32b09?d=identicon)[BrianHenryIE](/maintainers/BrianHenryIE)

---

Top Contributors

[![BrianHenryIE](https://avatars.githubusercontent.com/u/4720401?v=4)](https://github.com/BrianHenryIE "BrianHenryIE (12 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.9k227.1M273](/packages/sentry-sentry)[rollbar/rollbar

Monitors errors and exceptions and reports them to Rollbar

33723.7M82](/packages/rollbar-rollbar)[illuminate/log

The Illuminate Log package.

6224.3M518](/packages/illuminate-log)[open-telemetry/sdk

SDK for OpenTelemetry PHP.

2222.9M248](/packages/open-telemetry-sdk)[open-telemetry/api

API for OpenTelemetry PHP.

1833.0M214](/packages/open-telemetry-api)[pagemachine/typo3-formlog

Form log for TYPO3

23225.3k6](/packages/pagemachine-typo3-formlog)

PHPackages © 2026

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