Skip to content

Commit

Permalink
#4 use config for the input and output log defult false
Browse files Browse the repository at this point in the history
  • Loading branch information
xxl4 committed Jul 18, 2024
1 parent 952cacc commit 43ffb1f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/Config/Apis.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
'name' => 'Apis',
'version' => '1.0.7',
'versionNum' => '107',
'enable_input_log' => env("APIS_ENABLE_INPUT_LOG", true), // Enable input log for all requests
'enable_input_log' => env("APIS_ENABLE_INPUT_LOG", false), // Enable input log for all requests
'enable_output_log' => env("APIS_ENABLE_OUTPUT_LOG", false), // Enable output log for all requests
];
16 changes: 13 additions & 3 deletions src/Http/Middleware/AssignRequestId.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public function handle(Request $request, Closure $next): Response
Log::withContext([
'request-id' => $requestId
]);
if(config("apis.enable_input_log")) {
Log::info('Request', [

if(config("Apis.enable_input_log")) {
Log::info('Request Input', [
'request_id' => $requestId,
'method' => $request->getMethod(),
'url' => $request->getUri(),
Expand All @@ -32,9 +32,19 @@ public function handle(Request $request, Closure $next): Response
}

$response = $next($request);



$response->headers->set('Request-Id', $requestId);

if(config("Apis.enable_output_log")) {
Log::info('Response', [
'request_id' => $requestId,
'status' => $response->status(),
'output' => $response->getContent()
]);

}

return $response;
}
Expand Down

0 comments on commit 43ffb1f

Please sign in to comment.