Skip to content

Consolidate logging into a single println!() #2064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 31, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions src/middleware/log_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,23 @@ impl Handler for LogRequests {
.find::<u64>()
.map_or(String::new(), |l| format!(" metadata_length={}", l));

print!(
let slow_request = if response_time > 1000 {
" SLOW REQUEST"
} else {
""
};

let error = if let Err(ref e) = res {
format!(" error=\"{}\"", e)
} else {
String::new()
};

println!(
"at={level} method={method} path=\"{path}\" \
request_id={request_id} fwd=\"{ip}\" service={time_ms}ms \
status={status} user_agent=\"{user_agent}\"\
{metadata_length}",
{metadata_length}{error}{slow_request}",
level = level,
method = req.method(),
path = FullPath(req),
Expand All @@ -50,18 +62,10 @@ impl Handler for LogRequests {
request_id = request_header(req, "X-Request-Id"),
status = response_code,
metadata_length = metadata_length,
error = error,
slow_request = slow_request,
);

if let Err(ref e) = res {
print!(" error=\"{}\"", e.to_string());
}

if response_time > 1000 {
print!(" SLOW REQUEST");
}

println!();

res
}
}
Expand Down