https://github.com/oliwierptak/everon-logger
PSR-3 compilant, plugin oriented logger implementation based on Monolog
https://github.com/oliwierptak/everon-logger
logger monolog plugins semantic-versioning
Last synced: 7 days ago
JSON representation
PSR-3 compilant, plugin oriented logger implementation based on Monolog
- Host: GitHub
- URL: https://github.com/oliwierptak/everon-logger
- Owner: oliwierptak
- License: mit
- Created: 2020-11-13T19:15:26.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2023-08-04T13:41:02.000Z (about 2 years ago)
- Last Synced: 2025-09-03T12:57:03.120Z (about 1 month ago)
- Topics: logger, monolog, plugins, semantic-versioning
- Language: PHP
- Homepage:
- Size: 218 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# EveronLogger
[](https://github.com/oliwierptak/everon-logger/actions/workflows/main.yml)
Monolog based, PSR-3 compliant logger, with pluggable architecture and simple configuration.
## Features
- Pluggable architecture, semantically versioned
- Simple setup, with autocompletion
- One unified configuration schema
- Plugins can be grouped into sets to easily create customized and very specific loggers instances
- Monolog's handlers and processors constructors details and dependencies are never exposed
- Based on [Monolog v3.x](https://github.com/Seldaek/monolog)#### Simple Usage
Log everything at level `info` and above to `/tmp/example.log`.
```php
$streamPluginConfigurator = (new StreamLoggerPluginConfigurator)
->setLogLevel('info')
->setStreamLocation('/tmp/example.log');$configurator = (new LoggerConfigurator)
->add($streamPluginConfigurator);$logger = (new EveronLoggerFacade)->buildLogger($configurator);
$logger->info('lorem ipsum');
```Content of `/tmp/example.log`.
```
[2020-11-15T16:29:16.400318+00:00] everon-logger.INFO: lorem ipsum [] []
```## Configuration
The configuration is done by [simple data structures](https://github.com/oliwierptak/popo/) called `configurators`.
Each plugin configurator has its plugin specific settings.For example, to use syslog and file logging, setup the `StreamLoggerPluginConfigurator`
and `SyslogLoggerPluginConfigurator`.```php
$configurator = (new LoggerConfigurator)
->add(
(new StreamLoggerPluginConfigurator)
->setLogLevel('debug')
->setStreamLocation('/tmp/example.log')
)->add(
(new SyslogLoggerPluginConfigurator)
->setLogLevel('info')
->setIdent('everon-logger-ident'));
```### Logger Handler / Plugin
A logger plugin is used to create and configure corresponding Monolog's handler.
Besides `LoggerPluginInterface` a plugin can also implement `PluginFormatterInterface`,
in which case the custom formatter provided by the plugin will be used.### Setup with LoggerConfigurator
To set up a plugin with given handler, add it to the collection in `LoggerConfigurator` with `add()`.
For example, setup logging to a redis server and enable memory usage processor.
```php
$redisPluginConfigurator = new RedisLoggerPluginConfigurator;
$redisPluginConfigurator
->setLogLevel('info')
->setKey('redis-queue-test')
->requireRedisConnection()
->setHost('redis.host')
->setTimeout(10);$configurator = (new LoggerConfigurator)
->setName('everon-logger-example')
->add($redisPluginConfigurator)
->addProcessor(MemoryUsageProcessor::class);$logger = (new EveronLoggerFacade)->buildLogger($configurator);
$logger->info('lorem ipsum');
```Content of `redis-queue-test` in redis.
```
[2020-11-15T16:39:12.495319+00:00] everon-logger.INFO: lorem ipsum [] {"memory_usage":"6 MB"}
```## Logger processors
Add required processor classes to logger configurator with `addProcessor()`.
```php
$configurator = (new LoggerConfigurator)
->addProcessor(MemoryUsageProcessor::class)
->addProcessor(HostnameProcessor::class)
->addProcessor(...)
...
```## Plugins
### Basic
Set of plugins that require no extra vendor dependencies.
```
composer require everon/logger-basic
```[Repository](https://github.com/oliwierptak/everon-logger-basic)
### Gelf
Set of plugins for Graylog2 handlers.
```
composer require everon/logger-gelf
```[Repository](https://github.com/oliwierptak/everon-logger-gelf)
### Redis
Set of plugins for Redis handler.
[Repository](https://github.com/oliwierptak/everon-logger-redis)
```
composer require everon/logger-redis
```## Requirements
- PHP v8.1.x
- [Monolog v3.x](https://github.com/Seldaek/monolog)## Installation
```
composer require everon/logger
```_Note:_ You only need to install this package if you want to develop a plugin for `EveronLogger`.
Otherwise, install specific plugins. See above.