veronalabs / logger-wp
Logger for WordPress Based on PSR-3
v1.1
2022-06-20 15:12 UTC
Requires
- psr/log: ^1.1
This package is auto-updated.
Last update: 2024-11-13 12:39:28 UTC
README
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.
Features
- 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
Installation
Install the latest version with
composer require veronalabs/logger-wp
Basic Usage
<?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!');
Logger Exception handler
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()); }
About
Requirements
- LoggerWP
^1.0
works with PHP 7.4 or above.
Submitting bugs and feature requests
Bugs and feature request are tracked on GitHub
License
LoggerWP is licensed under the MIT License - see the LICENSE file for details