LoggerWP sends your logs to wp-content directory.
This library implements the PSR-3 interface that you can type-hint against in your own libraries to keep a maximum of interoperability.
- Protect the log files by .htaccess and hash the file name
- Support custom channel name
- Support custom log directory name
- Support admin log viewer
- Support PHP errors handler (TODO)
- Support logger exception handler
Install the latest version with
composer require veronalabs/logger-wp
<?php
use LoggerWp\Logger;
// create a log channel
$logger = new Logger([
'dir_name' => 'wpsms-logs', // wp-content/uploads/wpsms-logs/plugin-2022-06-11-37718a3a6b5ee53761291cf86edc9e10.log
'channel' => 'plugin', // default dev
'logs_days' => 30
]);
$logger->warning('Foo');
$logger->warning('Foo with context', [
'name' => 'Sarah',
'age' => '23',
]);
$logger->setChannel('api'); // wp-content/uploads/wpsms-logs/api-2022-06-11-37718a3a6b5ee53761291cf86edc9e10
$logger->error('Twilio encountered issue!');
use LoggerWp\Exception\LogerException;
try {
throw new LogerException('API error!');
} catch (Exception $e) {
}
Or
use LoggerWp\Logger;
try {
throw new Exception('API error!');
} catch (Exception $e) {
Logger::getInstance()->warning($e->getMessage());
}
- LoggerWP
^1.0
works with PHP 7.4 or above.
Bugs and feature request are tracked on GitHub
LoggerWP is licensed under the MIT License - see the LICENSE file for details