You are here

public static function Middleware::log in Auth0 Single Sign On 8.2

Middleware that logs requests, responses, and errors using a message formatter.

Parameters

LoggerInterface $logger Logs messages.:

MessageFormatter $formatter Formatter used to create message strings.:

string $logLevel Level at which to log requests.:

Return value

callable Returns a function that accepts the next handler.

File

vendor/guzzlehttp/guzzle/src/Middleware.php, line 185

Class

Middleware
Functions used to create and wrap handlers with handler middleware.

Namespace

GuzzleHttp

Code

public static function log(LoggerInterface $logger, MessageFormatter $formatter, $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);
        $logger
          ->log($logLevel, $message);
        return $response;
      }, function ($reason) use ($logger, $request, $formatter) {
        $response = $reason instanceof RequestException ? $reason
          ->getResponse() : null;
        $message = $formatter
          ->format($request, $response, $reason);
        $logger
          ->notice($message);
        return \GuzzleHttp\Promise\rejection_for($reason);
      });
    };
  };
}