artarts36/context-logger

There is no license information available for the latest version (0.1.0) of this package.

0.1.0 2023-05-21 17:08 UTC

This package is auto-updated.

Last update: 2024-10-30 02:11:00 UTC


README

License: MIT Latest Version Total Downloads

This package provides wrapper to psr/log for sharing context between different logs.

Implemented stores

Memory Store

Memory Store could be useful for sharing context in single web request or single console command running.

Creating an logger instance:

$logger = \ArtARTs36\ContextLogger\LoggerFactory::wrapInMemory(new class () extends \Psr\Log\AbstractLogger {
    public function log($level, \Stringable|string $message, array $context = []): void
    {
        var_dump($level, $message, $context);
    }
});

Apcu Store

Memory Store could be useful for sharing context for different web requests.

Creating an logger instance:

$logger = \ArtARTs36\ContextLogger\LoggerFactory::wrapInApcu(new class () extends \Psr\Log\AbstractLogger {
    public function log($level, \Stringable|string $message, array $context = []): void
    {
        var_dump($level, $message, $context);
    }
});

File Store

File Store could be useful for sharing context for different web requests or different console command runs.

Creating an logger instance:

$logger = \ArtARTs36\ContextLogger\LoggerFactory::wrapInFile(new class () extends \Psr\Log\AbstractLogger {
    public function log($level, \Stringable|string $message, array $context = []): void
    {
        var_dump($level, $message, $context);
    }
}, '/path/to/file.txt');

Null Store

Null Store could be useful for tests.

Creating an logger instance:

$logger = \ArtARTs36\ContextLogger\LoggerFactory::null();