arnapou/psr-log

Library - PSR-3.

v1.0.0 2024-09-09 16:34 UTC

This package is auto-updated.

Last update: 2024-09-09 14:39:36 UTC


README

pipeline coverage

KISS (Keep It Simple Stupid) PSR (PHP Standards Recommendations) classes.

Installation

composer require arnapou/psr-log

packagist 👉️ arnapou/psr-log

When it is worth to use this library

  • you need simple decorators, proxies, adapters, ... about PSR's
  • you need simple implementations covering the basics

Example PSR-3 Logger

File (rotation optional, inject your custom formatter or PSR-20 Clock Interface)

use Arnapou\Psr\Psr3Logger;

$logger = new Psr3Logger\FileLogger(
    logDirectory: '/path/of/logs',
    logName: 'app.log',
    rotation: Psr3Logger\Utils\Rotation::Every12Hours,
);

Decorators

use Arnapou\Psr\Psr3Logger\Decorator;

$logger = new Decorator\FixedLevelLogger($decorated, 'info');
$logger = new Decorator\MinimumLevelLogger($decorated, 'info');
$logger = new Decorator\PrefixLogger($decorated, '[My-App]');

// The ContextLogger helps to gather the same context for a bunch of logs (DRY).
// It avoids repeating the context array everywhere.
$logger = new Decorator\ContextLogger($decorated);
$logger->addContext(['user_id' => 42, 'name' => 'John Doe']);
$logger->debug('Hello');
$logger->info('World');

Php versions

DateRef8.38.2
09/09/20241.0.x, main××