Skip to content

Commit

Permalink
Merge pull request #270 from gregurco/move_logging_middlewares
Browse files Browse the repository at this point in the history
Move logging middlewares before plugins initialization
  • Loading branch information
gregurco committed Oct 2, 2019
2 parents b045b21 + 4caa396 commit b2e56e1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/DependencyInjection/EightPointsGuzzleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,6 @@ protected function createHandler(ContainerBuilder $container, string $clientName
$handlerStackServiceName = sprintf('eight_points_guzzle.handler_stack.%s', $clientName);
$container->setDefinition($handlerStackServiceName, $handler);

if ($logging) {
$this->defineLogMiddleware($container, $handler, $clientName);
$this->defineRequestTimeMiddleware($container, $handler, $clientName);
$this->attachSymfonyLogMiddlewareToHandler($handler);
}

if ($profiling) {
$this->defineProfileMiddleware($container, $handler, $clientName);
}
Expand All @@ -155,6 +149,12 @@ protected function createHandler(ContainerBuilder $container, string $clientName
}
}

if ($logging) {
$this->defineLogMiddleware($container, $handler, $clientName);
$this->defineRequestTimeMiddleware($container, $handler, $clientName);
$this->attachSymfonyLogMiddlewareToHandler($handler);
}

// goes on the end of the stack.
$handler->addMethodCall('unshift', [$eventExpression, 'events']);

Expand Down
3 changes: 3 additions & 0 deletions src/Middleware/ProfileMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Symfony\Component\Stopwatch\Stopwatch;

/**
* This Middleware is used to render request time slot on "Performance" tab in "Symfony Profiler".
*/
class ProfileMiddleware
{
/**
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/RequestTimeMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected function getOnStatsCallback($initialOnStats, $requestId) : \Closure

$this->dataCollector->addTotalTime((float)$stats->getTransferTime());

if ($requestId && $this->logger instanceof Logger) {
if (($this->logger instanceof Logger) && $requestId) {
$this->logger->addTransferTimeByRequestId($requestId, (float)$stats->getTransferTime());
}
};
Expand Down

0 comments on commit b2e56e1

Please sign in to comment.