Package to allow for simple logging with interface.

0.1.0 2024-03-28 16:02 UTC

This package is auto-updated.

Last update: 2024-04-28 16:28:51 UTC


README

vanrossum.dev Logo

Total Downloads Latest Stable Version License

WP Log

A simple package to write entries to a log file.

Installation

composer require jeffreyvanrossum/wp-log

Usage

You can setup your log with:

$log = new \Jeffreyvr\WPLog\Log('Your log');

You can define a custom file path, if you don't, the default is the wp-content/uploads/ folder with the file name being a sanitized version of your log name.

$log->setFilePath(wp_upload_dir()['basedir'] . '/logs/your-log-filename.log');

Writing to your log can be done like so:

$log->write('Your log message');

$log->write(['foo' => 'bar']);

You may clear your log with:

$log->clear();

The interface method will render an interface, which you can use to display the log somewhere in the admin area.

If you want to display the log page in the admin menu, you can call:

$log->interface()->inAdminMenu(slug: 'optional-slug', capability: 'manage_options');

Or if you want to add it as a plugin link instead:

$log->interface()->asPluginLink(basename: plugin_basename(__FILE__), slug: 'optional-slug');

You can instead also call $log->interface()->render() to render it somewhere you want.

To prevent your log from becoming very large, the default limit is set to 1000 items. You can overwrite this:

$log->setClearLimit(100);

// If you don't want to limit your log, you can pass 0.
$log->setClearLimit(0);

Contributors

License

MIT. Please see the License File for more information.