RRZE Log
WordPress Plugin for better logs for debugging purposes
by RRZE Webteam · github.com/rrze-webteam/rrze-log · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/rrze-webteam/rrze-log/archive/refs/heads/main.zipReadme
RRZE Log
WordPress Plugin
This plugin allows certain actions from plugins and themes to be logged into a log file, which may be necessary for further investigation.
Settings Menu (Multisite)
Network Admin / Log
Logging
Logging is done via the WP function do_action().
do_action(string $logHook, mixed $message [, array $context])
Parameters
$logHook
The name of the hook that logs the corresponding error level. Available hooks are:
- 'rrze.log.error'
- 'rrze.log.warning'
- 'rrze.log.notice'
- 'rrze.log.info'
$message
Can be a string or an array. If it is an array, the parameter $context will be ignored.
$context
An array or object that can be interpolated into the string value of the $message parameter.
Examples
// $message is a string.
// $context will not be applied.
do_action('rrze.log.info', 'Everything is working perfectly.');
// $message is an array.
// $context will be ignored.
do_action('rrze.log.error', ['plugin' => 'cms-basis', 'wp-error' => $wp_error->get_error_message()]);
// $message is a string.
// $context will be applied.
do_action('rrze.log.error', 'A WP error has occurred.', ['plugin' => 'cms-basis', 'wp-error' => $wp_error->get_error_message()]);
// $message is a formatted string that can be interpolated with the $context array.
do_action(
'rrze.log.error',
'Plugin: {plugin} WP Error: {wp-error}',
['plugin' => 'cms-basis', 'wp-error' => $wp_error->get_error_message()]
);
Another use case is logging an Exception that occurs during code execution.
try {
// ...
} catch(\Exception $exception) {
do_action('rrze.log.warning', ['exception' => $exception]);
if (defined('WP_DEBUG') && WP_DEBUG) {
throw $exception;
}
}
Retrieving Logs
Logs of the current day can be retrieved using WP’s apply_filters() function.
$logs = apply_filters('rrze.log.get', array $args);
Arguments
If $args is an empty array, all logs of the current day will be retrieved.
Default arguments array
$args = [
'search' => [],
'limit' => -1,
'offset' => 0,
];
Return Value
An array of records containing the logs.
Examples
// Get all logs for the current day.
$logs = apply_filters('rrze.log.get', []);
// Get all logs for the current day that contain the search term 'my-plugin'.
$logs = apply_filters('rrze.log.get', ['search' => ['my-plugin']]);
// Search based on a specific key (e.g., "level" and "plugin").
$logs = apply_filters(
'rrze.log.get',
['search' => ['"level":"error"', '"plugin":"my-plugin"']]
);
Notes
- Log files are stored in the directory
WP_CONTENT_DIR . '/log/' - The file name format is
rrze-log.logandwp-debug.log - The record format is JSON
Read the full README on GitHub →
Releases
These releases are tags only. The author does not attach a packaged zip, so there are no download counts to report.