Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jeffreyvr/wp-log
Simple package to write and display a log file in WordPress
https://github.com/jeffreyvr/wp-log
Last synced: 20 days ago
JSON representation
Simple package to write and display a log file in WordPress
- Host: GitHub
- URL: https://github.com/jeffreyvr/wp-log
- Owner: jeffreyvr
- License: mit
- Created: 2024-03-28T15:56:17.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-07-11T11:26:32.000Z (4 months ago)
- Last Synced: 2024-10-13T02:29:22.490Z (about 1 month ago)
- Language: PHP
- Size: 15.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# WP Log
A simple package to write entries to a log file.
## Installation
```bash
composer require jeffreyvanrossum/wp-log
```## Usage
You can setup your log with:
```php
$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.
```php
$log->setFilePath(wp_upload_dir()['basedir'] . '/logs/your-log-filename.log');
```Writing to your log can be done like so:
```php
$log->write('Your log message');$log->write(['foo' => 'bar']);
```You may clear your log with:
```php
$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:
```php
$log->interface()->inAdminMenu(slug: 'optional-slug', parent: 'tools.php');
```To set a custom capability use:
```php
$log->interface->setCapability('manage_options');
```Or if you want to add it as a plugin link instead:
```php
$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:
```php
$log->setClearLimit(100);// If you don't want to limit your log, you can pass 0.
$log->setClearLimit(0);
```## Contributors
* [Jeffrey van Rossum](https://github.com/jeffreyvr)
* [All contributors](https://github.com/jeffreyvr/wp-log/graphs/contributors)## License
MIT. Please see the [License File](/LICENSE) for more information.