Skip to content

Commit

Permalink
Merge pull request #23 from Mapudo/MAP-2890
Browse files Browse the repository at this point in the history
MAP-2890 As a Developer, I have detailed information about running Ak…
  • Loading branch information
kobelobster authored Dec 12, 2018
2 parents 20fade1 + bb8d40d commit 0907b18
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All Notable changes to `mapudo/guzzle-bundle` will be documented in this file.

Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.

## [2.2.1] - 2018-12-07
### Changed
- Fix `duration` in `LogMiddleware` parameter due to it needs to be passed by reference to a method to work properly

## [2.2.0] - 2018-11-29
### Changed
- Add `duration` property to be logged in `LogMiddleware` to keep track of the request duration
Expand Down
7 changes: 5 additions & 2 deletions src/Middleware/LogMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,16 @@ public function log(): \Closure
};

return $handler($request, $options)->then(
function (ResponseInterface $response) use ($logger, $request, $formatter, $duration) {
// `$duration` is passed by reference because at the time when the callback
// is registered the variable `$duration` is `null`.
// The stats callback is executed before the custom promise callbacks are executed.
function (ResponseInterface $response) use ($logger, $request, $formatter, &$duration) {
$message = $formatter->format($request, $response);
$logger->info($message, $this->buildContext($request, $response, $duration));

return $response;
},
function ($reason) use ($logger, $request, $formatter, $duration) {
function ($reason) use ($logger, $request, $formatter, &$duration) {
$response = $reason instanceof RequestException ? $reason->getResponse() : null;
$message = $formatter->format($request, $response, $reason);
$logger->error($message, $this->buildContext($request, $response, $duration));
Expand Down

0 comments on commit 0907b18

Please sign in to comment.