jd297/psr-logger

Simple implementation of PSR-3 (Logger Interface)

1.0.0 2024-02-06 00:05 UTC

This package is auto-updated.

Last update: 2024-04-09 12:21:33 UTC


README

Simple implementation of PSR-3 (Logger Interface).

Requirements

The following versions of PHP are supported by this version.

  • PHP ^8.1

Usage

Handler

All handlers implement the Jd297\Psr\Logger\Handler\HandlerInterface.

FileHandler

The FileHandler logs to a file that is specified in the first argument.

use Jd297\Psr\Logger\Handler\FileHandler;

$fileHandler = new FileHandler('[projectdir]/log/dev.log');

Logger

Instantiate a Logger with a Clock that implements Psr\Clock\ClockInterface and an array of handlers that implement Jd297\Psr\Logger\Handler\HandlerInterface.

use Jd297\Psr\Clock\SystemClock;
use Jd297\Psr\Logger\Logger;
use Psr\Log\LogLevel;

$logger = new Logger(new SystemClock(), [$fileHandler]);

$logger->log(LogLevel::INFO, 'User "{username}" created with email "{email}".', [
    'username' => 'john',
    'email' => 'john.doe@local.local',
]);

Composer

Scripts

Reformat code with PHP CS Fixer.

$ composer reformat

Test source code with PHPUnit.

$ composer unit

Analyse files with PHPStan (Level 9).

$ composer analyse

License

The BSD 2-Clause "Simplified" License (BSD-2-Clause). Please see License File for more information.