linkorb / flex-log
Simple wrapper around monolog-cascade adding practical utilities
v1.0.1
2023-02-03 09:26 UTC
Requires
- theorchard/monolog-cascade: ^0.6.0
Requires (Dev)
- phpunit/phpunit: ^8
This package is auto-updated.
Last update: 2024-10-30 01:59:21 UTC
README
FlexLog: flexible configurable logging for your applications
Allows reconfiguring the handlers, processor and formatters of your application's loggers through environment variables and config files.
FlexLog is a very thin wrapper around the awesome monolog-cascade library.
It adds:
- simple initialization based on the config file specified by the
FLEX_LOG
environment variable - ensures that all loggers your application expects are always added to Monolog's Registry, even if no cascade config file is used, or it misses a definition for that logger name.
Configuration
## Specify a cascade config file (yaml):
FLEX_LOG=/path/to/my/cascade.yaml
Usage
At the earliest entry point in your application (index.php, bootstap.php, etc), add the following line to initialize FlexLog:
use FlexLog\FlexLog; FlexLog::initFromEnv() FlexLog::ensureLoggers(['app', 'db', 'caching']); // ensures that loggers with these names exist and are registered
Then, from anywhere in your app, log to monolog as usual. For example by using Monolog's registry:
$username = 'joe'; \Monolog\Registry::app()->info("User {username} logged in", ['username' => $username]);
A fully working example can be found in the test cases in tests/
Tests
./vendor/bin/phpunit --bootstrap vendor/autoload.php tests/