diff --git a/src/HttpHandler/Guzzle6HttpHandler.php b/src/HttpHandler/Guzzle6HttpHandler.php index 3f86c60d2..0563aa91d 100644 --- a/src/HttpHandler/Guzzle6HttpHandler.php +++ b/src/HttpHandler/Guzzle6HttpHandler.php @@ -16,8 +16,8 @@ */ namespace Google\Auth\HttpHandler; -use Google\Auth\Logging\LogEvent; use Google\Auth\Logging\LoggingTrait; +use Google\Auth\Logging\RpcLogEvent; use GuzzleHttp\ClientInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -59,7 +59,7 @@ public function __invoke(RequestInterface $request, array $options = []) $requestEvent = null; if ($this->logger) { - $requestEvent = new LogEvent(); + $requestEvent = new RpcLogEvent(); $requestEvent->method = $request->getMethod(); $requestEvent->url = $request->getUri()->__toString(); @@ -76,7 +76,7 @@ public function __invoke(RequestInterface $request, array $options = []) $response = $this->client->send($request, $options); if ($this->logger) { - $responseEvent = new LogEvent($requestEvent->milliseconds); + $responseEvent = new RpcLogEvent($requestEvent->milliseconds); $responseEvent->headers = $response->getHeaders(); $responseEvent->payload = $response->getBody()->getContents(); @@ -103,7 +103,7 @@ public function async(RequestInterface $request, array $options = []) $requestEvent = null; if ($this->logger) { - $requestEvent = new LogEvent(); + $requestEvent = new RpcLogEvent(); $requestEvent->method = $request->getMethod(); $requestEvent->url = (string) $request->getUri(); @@ -121,7 +121,7 @@ public function async(RequestInterface $request, array $options = []) if ($this->logger) { $promise->then(function (ResponseInterface $response) use ($requestEvent) { - $responseEvent = new LogEvent($requestEvent->milliseconds); + $responseEvent = new RpcLogEvent($requestEvent->milliseconds); $responseEvent->headers = $response->getHeaders(); $responseEvent->payload = $response->getBody()->getContents(); diff --git a/src/Logging/LoggingTrait.php b/src/Logging/LoggingTrait.php index b0860e9e4..41c6304ae 100644 --- a/src/Logging/LoggingTrait.php +++ b/src/Logging/LoggingTrait.php @@ -24,7 +24,7 @@ trait LoggingTrait /** * @param LogEvent $event */ - private function logRequest(LogEvent $event): void + private function logRequest(RpcLogEvent $event): void { $debugEvent = [ 'timestamp' => $event->timestamp, @@ -60,7 +60,7 @@ private function logRequest(LogEvent $event): void /** * @param LogEvent $event */ - private function logResponse(LogEvent $event): void + private function logResponse(RpcLogEvent $event): void { $debugEvent = [ 'timestamp' => $event->timestamp, @@ -116,7 +116,7 @@ private function logResponse(LogEvent $event): void /** * @param LogEvent $event */ - private function logStatus(LogEvent $event): void + private function logStatus(RpcLogEvent $event): void { $infoEvent = [ 'timestamp' => $event->timestamp, diff --git a/src/Logging/LogEvent.php b/src/Logging/RpcLogEvent.php similarity index 97% rename from src/Logging/LogEvent.php rename to src/Logging/RpcLogEvent.php index b65550748..5adc691a3 100644 --- a/src/Logging/LogEvent.php +++ b/src/Logging/RpcLogEvent.php @@ -17,7 +17,7 @@ namespace Google\Auth\Logging; -class LogEvent +class RpcLogEvent { /** * Timestamp in format RFC3339 representing when this event ocurred @@ -120,6 +120,8 @@ class LogEvent public function __construct(null|float $startTime = null) { $this->timestamp = date(DATE_RFC3339); + + // Takes the micro time and convets it to millis $this->milliseconds = round(microtime(true) * 1000); if ($startTime) { diff --git a/tests/Logging/LoggingTraitTest.php b/tests/Logging/LoggingTraitTest.php index f162b4760..41dd56af0 100644 --- a/tests/Logging/LoggingTraitTest.php +++ b/tests/Logging/LoggingTraitTest.php @@ -17,8 +17,8 @@ namespace Google\Auth\Tests\Logging; -use Google\Auth\Logging\LogEvent; use Google\Auth\Logging\LoggingTrait; +use Google\Auth\Logging\RpcLogEvent; use Google\Auth\Logging\StdOutLogger; use Google\Auth\Tests\BaseTest; use Psr\Log\LoggerInterface; @@ -92,9 +92,9 @@ public function testLogResponse() $this->assertEquals($event->status, $parsedInfoEvent['jsonPayload']['response.status']); } - private function getNewLogEvent(): LogEvent + private function getNewLogEvent(): RpcLogEvent { - $event = new LogEvent(); + $event = new RpcLogEvent(); $event->clientId = 123; $event->method = 'get'; $event->url = 'test.com'; @@ -124,12 +124,12 @@ public function __construct() $this->logger = new StdOutLogger(); } - public function logRequestEvent(LogEvent $event): void + public function logRequestEvent(RpcLogEvent $event): void { $this->logRequest($event); } - public function logResponseEvent(LogEvent $event): void + public function logResponseEvent(RpcLogEvent $event): void { $this->logResponse($event); }