morningtrain / wp-logger
Logger interface
Requires
- morningtrain/wp-database: ^0.2.1
- psr/log: ^3.0
This package is auto-updated.
Last update: 2024-12-08 15:54:02 UTC
README
Make it easier to handle different levels of log.
Table of Contents
Introduction
Make it easier to handle different levels of log.
Getting Started
To get started install the package as described below in Installation.
To use the tool have a look at Usage
Installation
Install with composer
composer require morningtrain/wp-logger
Dependencies
Usage
Initializing package
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 ] );
Loggers
Each logger has the following methods, to register what level(s) that is needed:
->registerLevel($level)
->registerLevels([$level])
->registerAllLevels()
Database Logger
Make it possible to save logs to the database.
Class: \Morningtrain\WP\Logger\Loggers\DatabaseLogger
\Morningtrain\WP\Logger\Logger::databaseLogger()
File Logger
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)
Mail Logger
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)
Ray Logger
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()
Levels
\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
Use package
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
Contributing
Thank you for your interest in contributing to the project.
Bug Report
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.
Support Questions
We do not provide support for this package.
Pull Requests
- 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
Contributors
License
The MIT License (MIT). Please see License File for more information.
Developed by