bmwx591/request-logger

Library for logging application requests

v0.0.2 2025-03-13 18:51 UTC

This package is auto-updated.

Last update: 2025-05-18 19:49:20 UTC


README

MIT License

 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