Skip to content

Commit

Permalink
chore: update log messages of requests and responses
Browse files Browse the repository at this point in the history
Signed-off-by: Xin Liu <[email protected]>
  • Loading branch information
apepkuss committed Aug 13, 2024
1 parent 9c9aafc commit 116b5f4
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,11 @@ async fn handle_request(
.parse()
.unwrap();

info!(target: "request", "method: {}, endpoint: {}, http_version: {}, size: {}", method, path, version, size);
info!(target: "stdout", "method: {}, http_version: {}, content-length: {}", method, version, size);
info!(target: "stdout", "endpoint: {}", path);
} else {
info!(target: "request", "method: {}, endpoint: {}, http_version: {}", method, path, version);
info!(target: "stdout", "method: {}, http_version: {}", method, version);
info!(target: "stdout", "endpoint: {}", path);
}
}

Expand All @@ -503,26 +505,26 @@ async fn handle_request(
if status_code.as_u16() < 400 {
// log response
let response_version = format!("{:?}", response.version());
info!(target: "stdout", "response_version: {}", response_version);
let response_body_size: u64 = response.body().size_hint().lower();
info!(target: "stdout", "response_body_size: {}", response_body_size);
let response_status = status_code.as_u16();
let response_is_informational = status_code.is_informational();
info!(target: "stdout", "response_status: {}", response_status);
let response_is_success = status_code.is_success();
let response_is_redirection = status_code.is_redirection();
let response_is_client_error = status_code.is_client_error();
let response_is_server_error = status_code.is_server_error();

info!(target: "response", "version: {}, body_size: {}, status: {}, is_informational: {}, is_success: {}, is_redirection: {}, is_client_error: {}, is_server_error: {}", response_version, response_body_size, response_status, response_is_informational, response_is_success, response_is_redirection, response_is_client_error, response_is_server_error);
info!(target: "stdout", "response_is_success: {}", response_is_success);
} else {
let response_version = format!("{:?}", response.version());
error!(target: "stdout", "response_version: {}", response_version);
let response_body_size: u64 = response.body().size_hint().lower();
error!(target: "stdout", "response_body_size: {}", response_body_size);
let response_status = status_code.as_u16();
let response_is_informational = status_code.is_informational();
error!(target: "stdout", "response_status: {}", response_status);
let response_is_success = status_code.is_success();
let response_is_redirection = status_code.is_redirection();
error!(target: "stdout", "response_is_success: {}", response_is_success);
let response_is_client_error = status_code.is_client_error();
error!(target: "stdout", "response_is_client_error: {}", response_is_client_error);
let response_is_server_error = status_code.is_server_error();

error!(target: "response", "version: {}, body_size: {}, status: {}, is_informational: {}, is_success: {}, is_redirection: {}, is_client_error: {}, is_server_error: {}", response_version, response_body_size, response_status, response_is_informational, response_is_success, response_is_redirection, response_is_client_error, response_is_server_error);
error!(target: "stdout", "response_is_server_error: {}", response_is_server_error);
}
}

Expand Down

0 comments on commit 116b5f4

Please sign in to comment.