php-middleware / log-http-messages
PSR-15 middleware for log PSR-7 HTTP messages using PSR-3 logger
Installs: 29 441
Dependents: 3
Suggesters: 0
Security: 0
Stars: 8
Watchers: 2
Forks: 3
Open Issues: 2
Requires
- php: >=7.0
- psr/http-message: ^1.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
- psr/log: ^1.0
- zendframework/zend-diactoros: ^1.4 || ^2.0
Requires (Dev)
- phpunit/phpunit: ^6.1
This package is not auto-updated.
Last update: 2024-12-21 19:37:09 UTC
README
PSR-15 middleware for log PSR-7 HTTP messages using PSR-3 logger
This middleware provide framework-agnostic possibility to log request and response messages to PSR-3 logger.
Installation
composer require php-middleware/log-http-messages
To log http messages you need pass into LogRequestMiddleware
implementation of
PhpMiddleware\LogHttpMessages\Formatter\ServerRequestFormatter
,
PhpMiddleware\LogHttpMessages\Formatter\ResponseFormatter
,
instance Psr\Log\LoggerInterface
and add this middleware to your middleware runner.
You can also set log level (Psr\Log\LogLevel::INFO
as default) and log message (Request/Response
as default).
Provided implementation of formatters:
PhpMiddleware\LogHttpMessages\Formatter\EmptyMessageFormatter
,PhpMiddleware\LogHttpMessages\Formatter\ZendDiactorosToArrayMessageFormatter
,PhpMiddleware\LogHttpMessages\Formatter\ZendDiactorosToStringMessageFormatter
.
$formatter = PhpMiddleware\LogHttpMessages\Formatter\ZendDiactorosToArrayMessageFormatter(); $logMiddleware = new PhpMiddleware\LogHttpMessages\LogMiddleware($formatter, $formatter, $logger); $app = new MiddlewareRunner(); $app->add($logMiddleware); $app->run($request, $response);
It's just works with any modern php framework and logger!
Middleware tested on:
Middleware should works with:
And any other modern framework supported PSR-15 middlewares and PSR-7 and PSR-3 implementation logger.