Skip to content

Commit 49ebd8c

Browse files
committed
Adding time for the request
1 parent 6715e4a commit 49ebd8c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/LoggerPlugin.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,31 @@ public function __construct(LoggerInterface $logger, Formatter $formatter = null
3131
*/
3232
public function handleRequest(RequestInterface $request, callable $next, callable $first)
3333
{
34+
$start = microtime();
3435
$this->logger->info(sprintf("Sending request:\n%s", $this->formatter->formatRequest($request)), ['request' => $request]);
3536

36-
return $next($request)->then(function (ResponseInterface $response) use ($request) {
37+
return $next($request)->then(function (ResponseInterface $response) use ($request, $start) {
38+
$milliseconds = round(microtime() - $start/1000);
3739
$this->logger->info(
3840
sprintf("Received response:\n%s\n\nfor request:\n%s", $this->formatter->formatResponse($response), $this->formatter->formatRequest($request)),
3941
[
4042
'request' => $request,
4143
'response' => $response,
44+
'milliseconds' => $milliseconds,
4245
]
4346
);
4447

4548
return $response;
46-
}, function (Exception $exception) use ($request) {
49+
}, function (Exception $exception) use ($request, $start) {
50+
$milliseconds = round(microtime() - $start/1000);
4751
if ($exception instanceof Exception\HttpException) {
4852
$this->logger->error(
4953
sprintf("Error:\n%s\nwith response:\n%s\n\nwhen sending request:\n%s", $exception->getMessage(), $this->formatter->formatResponse($exception->getResponse()), $this->formatter->formatRequest($request)),
5054
[
5155
'request' => $request,
5256
'response' => $exception->getResponse(),
5357
'exception' => $exception,
58+
'milliseconds' => $milliseconds,
5459
]
5560
);
5661
} else {
@@ -59,6 +64,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
5964
[
6065
'request' => $request,
6166
'exception' => $exception,
67+
'milliseconds' => $milliseconds,
6268
]
6369
);
6470
}

0 commit comments

Comments
 (0)