bmwx591 / request-logger
Library for logging application requests
Requires
- php: ^7.4||^8.0
- psr/http-message: ^2.0
- psr/log: ^1.1
Requires (Dev)
- phpunit/phpunit: ^9.6
README
The simple template for create request logging system.
All that you need is to use some logger that implement Psr\Log\LoggerInterface
and request mapper that implements Bmwx591\RequestLogger\Mapper\RequestMapperInterface
for mapping log message and context. If you want to use some special rules to check if
you need to log one request or another you can add rules resolver implementation of
Bmwx591\RequestLogger\RulesResolver\RulesResolverInterface
. If you won`t add rules
resolver than all requests will be logged.
Logger works with wrapped requests and responses so you can write you own wrappers
by implement Bmwx591\RequestLogger\Logger\WrappedRequest
and
Bmwx591\RequestLogger\Logger\WrappedResponse
interfaces to add ability to work with
you type of requests and responses if they don`t implement PSR-7
Psr\Http\Message\RequestInterface
and Psr\Http\Message\ResponseInterface
.
Usage/Examples
use Bmwx591\RequestLogger\Logger\RequestLogger; $requestLogger = new RequestLogger( new SomeLogger(), // some implementation of Psr\Log\LoggerInterface $requestMapper, // implementation of RequestMapperInterface for map message and content for request $rulesResolver // implementation of RulesResolverInterface or null ); $requestLogger ->incomingRequest(<wrapped request>) ->outgoingResponse(<wrapped response>) ->addExternal(<ExternalRequest instance>) ->pushLogs();
Authors
Running Tests
To run tests, run the following command
vendor/bin/phpunit