antidot-fw/logger

Anti.Framework 日志适配器库

2.0.0 2023-07-02 09:30 UTC

README

Scrutinizer Code Quality Code Coverage Build Status Code Intelligence Status Maintainability

应用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));
    }
}