src/Core/Client/Adapter/Guzzle6Adapter.php
private static function log(LoggerInterface $logger, MessageFormatter $formatter, $logLevel = LogLevel::INFO)
    {
        return function (callable $handler) use ($logger, $formatter, $logLevel) {
            return function ($request, array $options) use ($handler, $logger, $formatter, $logLevel) {
                return $handler($request, $options)->then(
                    function ($response) use ($logger, $request, $formatter, $logLevel) {
                        $message = $formatter->format($request, $response);
                        $context = [
                            AbstractApiResponse::X_CORRELATION_ID => $response->getHeader(
                                AbstractApiResponse::X_CORRELATION_ID
                            )
                        ];
                        $logger->log($logLevel, $message, $context);
                        return $response;
                    },
                    function ($reason) use ($logger, $request, $formatter) {
                        $response = null;
                        $context = [];
                        if ($reason instanceof RequestException) {
                            $response = $reason->getResponse();
                            if (!is_null($response)) {
                                $context[AbstractApiResponse::X_CORRELATION_ID] = $response->getHeader(
                                    AbstractApiResponse::X_CORRELATION_ID
                                );
                            }
                        }
                        $message = $formatter->format($request, $response, $reason);
                        $logger->notice($message, $context);
                        return \GuzzleHttp\Promise\rejection_for($reason);
                    }
                );
            };
        };
    }
private static function log(LoggerInterface $logger, MessageFormatter $formatter, $logLevel = LogLevel::INFO)
    {
        return function (callable $handler) use ($logger, $formatter, $logLevel) {
            return function ($request, array $options) use ($handler, $logger, $formatter, $logLevel) {
                return $handler($request, $options)->then(
                    function ($response) use ($logger, $request, $formatter, $logLevel) {
                        $message = $formatter->format($request, $response);
                        $context = [
                            AbstractApiResponse::X_CORRELATION_ID => $response->getHeader(
                                AbstractApiResponse::X_CORRELATION_ID
                            )
                        ];
                        $logger->log($logLevel, $message, $context);
                        return $response;
                    },
                    function ($reason) use ($logger, $request, $formatter) {
                        $response = null;
                        $context = [];
                        if ($reason instanceof RequestException) {
                            $response = $reason->getResponse();
                            if (!is_null($response)) {
                                $context[AbstractApiResponse::X_CORRELATION_ID] = $response->getHeader(
                                    AbstractApiResponse::X_CORRELATION_ID
                                );
                            }
                        }
                        $message = $formatter->format($request, $response, $reason);
                        $logger->notice($message, $context);
                        return \GuzzleHttp\Promise\rejection_for($reason);
                    }
                );
            };
        };
    }
private static function log ( LoggerInterface $ logger , MessageFormatter $ formatter , $ logLevel = LogLevel :: INFO ) { return function ( callable $ handler ) use ( $ logger , $ formatter , $ logLevel ) { return function ( $ request , array $ options ) use ( $ handler , $ logger , $ formatter , $ logLevel ) { return $ handler ( $ request , $ options ) -> then ( function ( $ response ) use ( $ logger , $ request , $ formatter , $ logLevel ) { $ message = $ formatter -> format ( $ request , $ response ) ; $ context = [ AbstractApiResponse :: X_CORRELATION_ID => $ response -> getHeader ( AbstractApiResponse :: X_CORRELATION_ID ) ] ; $ logger -> log ( $ logLevel , $ message , $ context ) ; return $ response ; } , function ( $ reason ) use ( $ logger , $ request , $ formatter ) { $ response = null ; $ context = [ ] ; if ( $ reason instanceof RequestException ) { $ response = $ reason -> getResponse ( ) ; if ( ! is_null ( $ response ) ) { $ context [ AbstractApiResponse :: X_CORRELATION_ID ] = $ response -> getHeader ( AbstractApiResponse :: X_CORRELATION_ID ) ; } } $ message = $ formatter -> format ( $ request , $ response , $ reason ) ; $ logger -> notice ( $ message , $ context ) ; return \ GuzzleHttp \ Promise \ rejection_for ( $ reason ) ; } ) ; } ; } ; }
Middleware that logs requests, responses, and errors using a message
formatter.

@param LoggerInterface  $logger Logs messages.
@param MessageFormatter $formatter Formatter used to create message strings.
@param string           $logLevel Level at which to log requests.

@return callable Returns a function that accepts the next handler.
Middleware that logs requests responses and errors using a message formatter .