From 86326f0a77c3b1d5d4e555d638b0c089c51c6962 Mon Sep 17 00:00:00 2001 From: Paolo <149602456+pdtfh@users.noreply.github.com> Date: Thu, 30 Nov 2023 14:55:07 +0100 Subject: [PATCH] adds additional request logging --- .env.example | 7 ++++++- src/routes/request.rs | 18 +++++++++++------- src/routes/response.rs | 6 ++++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/.env.example b/.env.example index c9b70b6..cc7db71 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,6 @@ -REDIS_URL=redis://localhost \ No newline at end of file +REDIS_URL=redis://localhost +# REDIS_HOST=localhost +# REDIS_PORT=6379 +# REDIS_USERNAME=default +# REDIS_USE_TLS=true +# REDIS_PASSWORD= \ No newline at end of file diff --git a/src/routes/request.rs b/src/routes/request.rs index d444b6a..0a10787 100644 --- a/src/routes/request.rs +++ b/src/routes/request.rs @@ -73,10 +73,17 @@ async fn get_request( .await .map_err(handle_redis_error)?; - serde_json::from_slice(&value.unwrap()) - .map_or(Err(StatusCode::INTERNAL_SERVER_ERROR), |value| { + serde_json::from_slice(&value.unwrap()).map_or( + Err(StatusCode::INTERNAL_SERVER_ERROR), + |value| { + tracing::info!( + "{}", + format!("Successfully retrieved /request: {request_id}") + ); + Ok(Json(value)) - }) + }, + ) } async fn insert_request( @@ -107,10 +114,7 @@ async fn insert_request( .await .map_err(handle_redis_error)?; - tracing::info!( - "{}", - format!("Successfully processed /request: {request_id}") - ); + tracing::info!("{}", format!("Successfully stored /request: {request_id}")); Ok(Json(CustomResponse { request_id })) } diff --git a/src/routes/response.rs b/src/routes/response.rs index d825ae2..3688569 100644 --- a/src/routes/response.rs +++ b/src/routes/response.rs @@ -49,6 +49,10 @@ async fn get_response( return serde_json::from_slice(&value).map_or( Err(StatusCode::INTERNAL_SERVER_ERROR), |value| { + tracing::info!( + "{}", + format!("Successfully retrieved /response: {request_id}") + ); Ok(Json(Response { response: value, status: RequestStatus::Completed, @@ -118,5 +122,7 @@ async fn insert_response( .await .map_err(handle_redis_error)?; + tracing::info!("{}", format!("Successfully stored /response: {request_id}")); + Ok(StatusCode::CREATED) }