PHPackages                             dittto/symfony-request-logger - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. dittto/symfony-request-logger

ActiveSymfony-bundle[Logging &amp; Monitoring](/categories/logging)

dittto/symfony-request-logger
=============================

Handles logging external requests via guzzle

1.0.0(8y ago)219.5k↓50%MITPHP

Since Jul 10Pushed 8y agoCompare

[ Source](https://github.com/dittto/symfony-request-logger)[ Packagist](https://packagist.org/packages/dittto/symfony-request-logger)[ RSS](/packages/dittto-symfony-request-logger/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

Symfony request logger
======================

[](#symfony-request-logger)

What is it?
-----------

[](#what-is-it)

Any apps we write will, quite often, have cause to make external calls to either our own, or third-party, APIs. This Symfony bundle makes it easy to track how long these requests are taking and return the result via either monolog and/or an additional JSON object that's appended to your output when Symfony's in debug mode.

It works by adding extra middleware to Guzzle so we can track when a request is made and either succeeds or fails, and then storing these logs for later output.

How to set it up
----------------

[](#how-to-set-it-up)

### Basic setup

[](#basic-setup)

There are a few different options for using this request logger. The most simple is to log all requests made via Guzzle, and then recall the logs later.

To do this, add / update the following services. If you've already got a Guzzle service, then update it as required:

```
services:
    dittto.request_logger.alias:
        alias: 'dittto.request_logger'

    http_client:
        class: GuzzleHttp\Client
        arguments:
          - handler: '@http_client.handlerstack'
            connect_timeout: 5
            timeout: 5

    http_client.handlerstack:
        class: GuzzleHttp\HandlerStack
        factory: [ GuzzleHttp\HandlerStack, 'create' ]
        calls:
          - [ 'push', [ '@dittto.request_logger.middleware.request' ] ]
```

What does this do then? The first service is to define which version of the request logger we're going to use. `dittto.request_logger` is the most basic form of `LoggerInterface` that simply stores all requests for later.

After that, we create a Guzzle client, and then make sure our middleware has been added to it, so we can store our API request attempts.

To use this, you'd probably do something like:

```
services:
    test_controller:
            class: AppBundle\Controller\TestController
            arguments: [ '@http_client', '@dittto.request_logger.alias' ]
```

```
