public static function Middleware::log in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/guzzlehttp/guzzle/src/Middleware.php \GuzzleHttp\Middleware::log()
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 184
Class
- Middleware
- Functions used to create and wrap handlers with handler middleware.
Namespace
GuzzleHttpCode
public 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);
$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);
});
};
};
}