diff --git a/src/M6Web/Bundle/LogBridgeBundle/Formatter/DefaultFormatter.php b/src/M6Web/Bundle/LogBridgeBundle/Formatter/DefaultFormatter.php index 02ad66c..f36ed1a 100644 --- a/src/M6Web/Bundle/LogBridgeBundle/Formatter/DefaultFormatter.php +++ b/src/M6Web/Bundle/LogBridgeBundle/Formatter/DefaultFormatter.php @@ -77,14 +77,15 @@ public function getLogContent(Request $request, Response $response, array $optio // Render post parameters if (array_key_exists('post_parameters', $options) - && $options['post_parameters'] == true + && $options['post_parameters'] === true && in_array($request->getMethod(), ['POST', 'PUT', 'PATCH'])) { $responseContent .= "Post parameters\n"; $responseContent .= $this->formatParameters($request->request->all()); } // Render response body content - if (isset($options['response_body'])) { + if (array_key_exists('response_body', $options) + && $options['response_body'] === true) { $responseContent .= "Response body\n------------------------\n"; $responseContent .= $response->getContent()."\n"; } diff --git a/src/M6Web/Bundle/LogBridgeBundle/Tests/Units/Formatter/DefaultFormatter.php b/src/M6Web/Bundle/LogBridgeBundle/Tests/Units/Formatter/DefaultFormatter.php index f45f3d4..c078719 100644 --- a/src/M6Web/Bundle/LogBridgeBundle/Tests/Units/Formatter/DefaultFormatter.php +++ b/src/M6Web/Bundle/LogBridgeBundle/Tests/Units/Formatter/DefaultFormatter.php @@ -83,6 +83,9 @@ public function testProvider(): void ->string($provider->getLogContent($request, $response, ['response_body' => true])) ->contains("Response body\n") ->contains($response->getContent()) + ->string($provider->getLogContent($request, $response, ['response_body' => false])) + ->notContains("Response body\n") + ->notContains($response->getContent()) ->array($logContext = $provider->getLogContext($request, $response, [])) ->hasSize(7) ->hasKeys(['environment', 'route', 'method', 'status', 'user', 'key', 'uri'])