Overview
Description
Caldera Logger is a PSR-3
implementation.
As with the other Caldera components it has been built to be swappable and modular, which means you can change it for any other PSR-3
implementation should you like to.
Installation
The easisest way to install it is to use Composer:
composer require vecode/caldera-logger
Requires
php: >=8.1
ext-mbstring: *
psr/log: ^3.0"
Basic usage
Getting started
Just create an instance of Logger
, for that you will need to pass an instance of an AdapterInterface
, for example a FileAdapter
:
use Caldera\Logger\Logger;
use Caldera\Logger\Adapter\FileAdapter;
$adapter = new FileAdapter($path);
$logger = new Logger($adapter);
You may also specify a LogLevel
for each adapter so that it only logs messages from the given severity and upwards:
use Caldera\Logger\Logger;
use Caldera\Logger\Adapter\FileAdapter;
$adapter = new FileAdapter($path);
$adapter->setLevel(LogLevel::INFO);
$logger = new Logger($adapter);
Finally, you can attach several adapters by using the attach
method and passing an AdapterInterface
instance.
Once instantiated, you just need to call one of the following methods:
$logger->emergency(string $message, array $context = []);
$logger->alert(string $message, array $context = []);
$logger->critical(string $message, array $context = []);
$logger->error(string $message, array $context = []);
$logger->warning(string $message, array $context = []);
$logger->notice(string $message, array $context = []);
$logger->info(string $message, array $context = []);
$logger->debug(string $message, array $context = []);
According to the PSR-3
specification, each level corresponds to one of the following scenarios:
emergency
- System is unusablealert
- Action must be taken immediatelycritical
- Critical conditionserror
- Runtime errors that do not require immediate action but should typically be logged and monitoredwarning
- Exceptional occurrences that are not errorsnotice
- Normal but significant eventsinfo
- Interesting eventsdebug
- Detailed debug information