arnapou / psr-log
v1.0.0
2024-09-09 16:34 UTC
Requires
- php: ~8.2.0 || ~8.3.0
- arnapou/psr-clock: ^1.0
- psr/log: ^2.0 || ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.52
- phpstan/extension-installer: ^1.3
- phpstan/phpstan: ^1.10
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
- phpstan/phpstan-strict-rules: ^1.5
- phpunit/php-code-coverage: ^11.0
- phpunit/phpunit: ^11.0
Provides
README
KISS (Keep It Simple Stupid) PSR (PHP Standards Recommendations) 类。
安装
composer require arnapou/psr-log
packagist 👉️ arnapou/psr-log
何时使用此库
- 你需要简单的装饰器、代理、适配器等关于PSR的
- 你需要简单的实现,涵盖基本功能
示例 PSR-3 日志记录器
文件(可选,注入您的自定义格式化器或PSR-20 时钟接口)
use Arnapou\Psr\Psr3Logger;
$logger = new Psr3Logger\FileLogger(
logDirectory: '/path/of/logs',
logName: 'app.log',
rotation: Psr3Logger\Utils\Rotation::Every12Hours,
);
装饰器
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版本
日期 | 引用 | 8.3 | 8.2 |
---|---|---|---|
09/09/2024 | 1.0.x, 主分支 | × | × |