Download the PHP package brianhenryie/bh-wp-cli-logger without Composer
On this page you can find all versions of the php package brianhenryie/bh-wp-cli-logger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download brianhenryie/bh-wp-cli-logger
More information about brianhenryie/bh-wp-cli-logger
Files in brianhenryie/bh-wp-cli-logger
Package bh-wp-cli-logger
Short Description A PSR logger for WP CLI commands.
License GPL-2.0-or-later
Informations about the package bh-wp-cli-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
Operation
- It is just a PSR Logger Interface 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:
Try it out
The test plugin CLI command has two options, levels and message:
Delete the Docker containers afterwards:
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
Level Filtering
I imagine there is a Composer package that provides the same utility as WooCommerce's WC_Logger::should_handle() 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 >=2.0
This currently requires "psr/log": "^1.0"
. v2.0 requires PHP 8.0 and introduces parameter types; 3.0 then introduces return types.
Context
Context is not printed.
See Also
- BH WP Logger – this class was extracted from that
- BH Color Logger – like this, for unit tests