Make it easier to handle different levels of log.
Make it easier to handle different levels of log.
To get started install the package as described below in Installation.
To use the tool have a look at Usage
Install with composer
composer require morningtrain/wp-logger
First of all, to get \Morningtrain\WP\Logger\Loggers\DatabaseLogger
to work, the migration needs to be run. This is done be running the following method:
\Morningtrain\WP\Logger\Logger::initializeMigration()
Initialize \Morningtrain\WP\Logger\Logger
with a slug and an array of the loggers that needs to be registered.
For each logger, there is some levels, that can be registered for the specific logger.
\Morningtrain\WP\Logger\Logger::registerLoggers(
'logger',
[
// Loggers
]
);
Each logger has the following methods, to register what level(s) that is needed:
->registerLevel($level)
->registerLevels([$level])
->registerAllLevels()
Make it possible to save logs to the database.
Class: \Morningtrain\WP\Logger\Loggers\DatabaseLogger
\Morningtrain\WP\Logger\Logger::databaseLogger()
Make it possible to save logs to a file.
Class: \Morningtrain\WP\Logger\Loggers\FileLogger
Parameters in callback:
string $filename
\Morningtrain\WP\Logger\Logger::fileLogger($filename)
Make it possible to send logs to multiple emails.
Class: \Morningtrain\WP\Logger\Loggers\MailLogger
Parameters in callback:
array $emails
\Morningtrain\WP\Logger\Logger::mailLogger($emails)
Make it possible to send logs to a Ray client.
Class: \Morningtrain\WP\Logger\Loggers\RayLogger
Parameters in callback:
bool $backtrace // Optional. If true, it will add backtrace
\Morningtrain\WP\Logger\Logger::rayLogger()
\Psr\Log\LogLevel::EMERGENCY
\Psr\Log\LogLevel::ALERT
\Psr\Log\LogLevel::CRITICAL
\Psr\Log\LogLevel::ERROR
\Psr\Log\LogLevel::WARNING
\Psr\Log\LogLevel::NOTICE
\Psr\Log\LogLevel::INFO
\Psr\Log\LogLevel::DEBUG
To get the Logger, that has been registered, the method \Morningtrain\WP\Logger\Logger::getLogger($slug)
, where the slug is needed.
When the logger is collected, there is a method, for each level, that can be call:
\Morningtrain\WP\Logger\Logger::getLogger('logger')
->emergency()
->alert()
->critical()
->error()
->warning()
->notice()
->info()
->debug()
Each of these methods that:
string $message
array $context // Optional
Thank you for your interest in contributing to the project.
If you found a bug, we encourage you to make a pull request.
To add a bug report, create a new issue. Please remember to add a telling title, detailed description and how to reproduce the problem.
We do not provide support for this package.
- Fork the Project
- Create your Feature Branch (git checkout -b feature/AmazingFeature)
- Commit your Changes (git commit -m 'Add some AmazingFeature')
- Push to the Branch (git push origin feature/AmazingFeature)
- Open a Pull Request
The MIT License (MIT). Please see License File for more information.