antidot-fw / logger
Anti.Framework logger adapter library
Fund package maintenance!
kpicaza
Requires
- php: ^7.4.0|^8.0
- psr/http-server-middleware: ^1.0
- psr/log: ^1.1
Requires (Dev)
- phpro/grumphp: ~0.17 || ~1.0
- phpstan/phpstan: ^0.11.5 || ^0.12.0
- phpunit/phpunit: ^8.0 || ^9.0
- squizlabs/php_codesniffer: ^3.4
- wshafer/psr11-monolog: @dev
Suggests
- wshafer/psr11-monolog: Allow using middleware with monolog implementation using MonologFactory class
README
Application PSR-15 logger middleware:
- RequestLoggerMiddleware
- ExceptionLoggerMiddleware
Installation
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)); } }
Using factory:
Config
See wshafer/psr11-monolog for complete config reference, it allows using some different handlers
factory
<?php use Antidot\Logger\Container\MonologFactory; use Psr\Log\LoggerInterface; $factory = new MonologFactory(); $logger = $factory->__invoke($container); $container->set(LoggerInterface::class, $logger);