gokure / hyperf-http-logger
Log HTTP requests and responses for Hyperf.
Requires
- php: >= 7.2
- ext-swoole: >= 4.4
- hyperf/contract: ^1.0|^2.0
- hyperf/di: ^1.0|^2.0
- hyperf/http-server: ^1.0|^2.0
- hyperf/utils: ^1.0|^2.0
- monolog/monolog: ^2.0
- psr/container: ^1.0
- psr/log: ^1.0
Requires (Dev)
- hyperf/testing: ^1.0|^2.0
- mockery/mockery: ^1.0
- phpunit/phpunit: ^7.0.0
- roave/security-advisories: dev-master
- swoole/ide-helper: ^4.5
README
A middleware which can log incoming requests and responses to the log.
Installation
Require the gokure/hypref-http-logger
package in your composer.json
and update your dependencies:
composer require gokure/hypref-http-logger
Optionally you can publish the configuration file with:
php bin/hyperf.php vendor:publish gokure/hypref-http-logger
Usage
To allow HTTP Logger in your application, add the HttpLoggerMiddleware
middleware at the top of the property of config/autoload/middlewares.php
file in the config (see Configuration below):
'http' => [ \Gokure\HttpLogger\HttpLoggerMiddleware::class, ... ],
Also, to allow HTTP Logger for exception responses, you need add the HttpLoggerExceptionHandler
handler at the bottom of the property of config/autoload/exceptions.php
file:
'handler' => [ 'http' => [ ... Gokure\HttpLogger\HttpLoggerExceptionHandler::class, ], ],
Note: No response logged, if
$this->stopPropagation()
is used in the previous exception handlers.
TODO
- To filter secret body of requests and responses.
- Add test cases.
License
Released under the MIT License, see LICENSE.