Application PSR-15 logger middleware:
- RequestLoggerMiddleware
- ExceptionLoggerMiddleware
Require package with composer package manager.
composer require antidot-fw/logger
Add both Middleware to your 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);
Using Zend Config Aggregator
It installs the library automatically
To use both middlewares in Zend Expressive you need to create factory classes
<?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));
}
}