koded / logging
A simple standalone logging facility with several log processors
Requires
- php: ^8.1
- koded/stdlib: ^5|^6
- psr/log: ^3
Requires (Dev)
- mikey179/vfsstream: ^1
- phpbench/phpbench: @dev
- phpunit/phpunit: ^9
README
A simple message logging library that implements PSR-3 with several log processors. It supports multiple log writers that can be set separately and process messages based on the log level.
Installation
Use composer and run
composer require koded/logging
or add it manually in your current composer.json
{ "require": { "koded/logging": "^3" } }
Usage
<?php $settings = [ [ ['class' => Cli::class, 'levels' => Log::ERROR], ['class' => File::class, 'levels' => Log::INFO] ] ]; $log = new Log(...$settings); // This message is processed by Cli and File $log->alert('The message with {variable}', ['variable' => 'useful info']); // This message won't be processed by Cli // because it's level is below ERROR, // but File will handle it $log->warning("You don't see anything");
Configuration
Processor default directives
Every log processor has it's own set of configuration directives.
The table shows log parameters in the classes.
Levels example
The messages are filtered with bitwise operator against the levels
value.
Every processor will filter out the messages as defined in it's levels directive.
For instance, to log only WARNING, INFO and ERROR messages, set levels to
<?php [..., ['levels' => Log::WARN | Log::INFO | Log::ERROR, ...]],
Tips:
- every processor is configured separately
- if you want to process all log levels, skip the
levels
value or set it to -1 (by default) - if you want to suppress a specific processor, set it's level to 0
Processors
Benchmarks and tests
vendor/bin/phpbench run --report=default vendor/bin/phpunit
License
The code is distributed under the terms of The 3-Clause BSD license.