piotrpress / logger
This library is compatible with PSR-3 file logger implementation.
v1.0.0
2021-03-23 20:53 UTC
Requires
- php: >=7.4
- psr/log: ^1.1.3
This package is not auto-updated.
Last update: 2024-05-07 21:26:41 UTC
README
This library is compatible with PSR-3 file logger implementation.
Installation
composer require piotrpress/logger
Usage
require __DIR__ . '/vendor/autoload.php'; use PiotrPress\Logger; $logger = new Logger( '/logs/error.log' ); $logger->error( 'Error example' );
Saves: [2021-03-23 23:15:00] [error] Error example
to file: /logs/error.log
Format
Logger supports context
array via constructor and/or log functions optional parameter.
Defaults:
- format:
"[{date}] [{level}] {message}\n"
- date:
date( 'Y-m-d G:i:s' )
- level: log level, with which the method has been called
- message: message, with which the method has been called
All additional array values, evaluated to string, can be used in format
via corresponding keys put between a single opening brace {
and a single closing brace }
.
Log Levels
Logger supports eight methods to write logs to the eight RFC 5424 levels (debug
, info
, notice
, warning
, error
, critical
, alert
, emergency
) and a ninth method log
, which accepts a log level as the first argument.