@@ -31,26 +31,31 @@ public function __construct(LoggerInterface $logger, Formatter $formatter = null
31
31
*/
32
32
public function handleRequest (RequestInterface $ request , callable $ next , callable $ first )
33
33
{
34
+ $ start = microtime ();
34
35
$ this ->logger ->info (sprintf ("Sending request: \n%s " , $ this ->formatter ->formatRequest ($ request )), ['request ' => $ request ]);
35
36
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 );
37
39
$ this ->logger ->info (
38
40
sprintf ("Received response: \n%s \n\nfor request: \n%s " , $ this ->formatter ->formatResponse ($ response ), $ this ->formatter ->formatRequest ($ request )),
39
41
[
40
42
'request ' => $ request ,
41
43
'response ' => $ response ,
44
+ 'milliseconds ' => $ milliseconds ,
42
45
]
43
46
);
44
47
45
48
return $ response ;
46
- }, function (Exception $ exception ) use ($ request ) {
49
+ }, function (Exception $ exception ) use ($ request , $ start ) {
50
+ $ milliseconds = round (microtime () - $ start /1000 );
47
51
if ($ exception instanceof Exception \HttpException) {
48
52
$ this ->logger ->error (
49
53
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 )),
50
54
[
51
55
'request ' => $ request ,
52
56
'response ' => $ exception ->getResponse (),
53
57
'exception ' => $ exception ,
58
+ 'milliseconds ' => $ milliseconds ,
54
59
]
55
60
);
56
61
} else {
@@ -59,6 +64,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
59
64
[
60
65
'request ' => $ request ,
61
66
'exception ' => $ exception ,
67
+ 'milliseconds ' => $ milliseconds ,
62
68
]
63
69
);
64
70
}
0 commit comments