PiotrPress / logger

This library is compatible with PSR-3 file logger implementation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Logger

This library is compatible with PSR-3 file logger implementation.

Installation

composer require piotrpress/logger

Example

require __DIR__ . '/vendor/autoload.php';

use PiotrPress\Logger;
use PiotrPress\Logger\FileHandler;
use PiotrPress\Logger\ErrorLogHandler;

$logger = new Logger(
    new FileHandler( __DIR__ . '/' . date( 'Y-m-d' ) . '.log' ),
    new ErrorLogHandler() 
);
    
$logger->error( '[{module}] Example error', [ 'module' => 'Core' ] );

Saves: [error] [Core] Example error to file: {Y-m-d}.log and sends to PHP error log.

Logger

Logger take any number of handlers implementing HandlerInterface as constructor arguments.

Handlers

NOTE: Both handlers support optional FormatterInterface parameter.

Formatters

NOTE: Both formatters support optional path to template parameter.

Levels

Logger supports eight log 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.

Context

All Logger log methods supports optional context array parameter.

All additional context array values, evaluated to string, can be used in message via corresponding keys put between a single opening brace { and a single closing brace } according to PSR-3 guidelines.

Context values can be also used in templates files as regular PHP variables.

Requirements

Supports PHP >= 7.4 version.

License

GPL3.0

About

This library is compatible with PSR-3 file logger implementation.

License:GNU General Public License v3.0


Languages

Language:PHP 100.0%