antidot-fw / logger
Anti.Framework 日志适配器库
2.0.0
2023-07-02 09:30 UTC
Requires
- php: ~8.1.0 || ~8.2.0
- psr/http-server-middleware: ^1.0
- psr/log: ^3.0
Requires (Dev)
- icanhazstring/composer-unused: ^0.8.9
- infection/infection: ^0.27
- phpro/grumphp: ~0.17 || ~1.0
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^8.0 || ^9.0
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2024-08-31 00:36:12 UTC
README
应用PSR-15日志中间件
- RequestLoggerMiddleware
- ExceptionLoggerMiddleware
安装
需要使用Composer包管理器安装包。
composer require antidot-fw/logger
将两个中间件添加到您的Pipeline中
<?php // with Antidot Framework, Zend Expressive or Zend Stratigility $app->pipe(\Antidot\Logger\Application\Http\Middleware\ExceptionLoggerMiddleware::class); $app->pipe(\Antidot\Logger\Application\Http\Middleware\RequestLoggerMiddleware::class);
使用Zend Config Aggregator
它会自动安装库
要在Zend Expressive中使用这两个中间件,您需要创建工厂类
<?php // src/App/Container/ExceptionLoggerMiddlewareFactory.php namespace App\Container; use Antidot\Logger\Application\Http\Middleware\ExceptionLoggerMiddleware; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; class ExceptionLoggerMiddlewareFactory { public function __invoke(ContainerInterface $container) { return new ExceptionLoggerMiddleware($container->get(LoggerInterface::class)); } }
<?php // src/App/Container/RequestLoggerMiddlewareFactory.php namespace App\Container; use Antidot\Logger\Application\Http\Middleware\RequestLoggerMiddleware; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; class RequestLoggerMiddlewareFactory { public function __invoke(ContainerInterface $container) { return new RequestLoggerMiddleware($container->get(LoggerInterface::class)); } }