Skip to content

Commit 6a602e6

Browse files
committed
Switch Debug middleware from println! to debug!
All this output is annoying during local development, and can be easily accessed if necessary via the `RUST_LOG` environment variable.
1 parent 6ed64aa commit 6a602e6

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/middleware.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ pub fn build_middleware(app: Arc<App>, endpoints: RouteBuilder) -> MiddlewareBui
4646
}
4747

4848
if env == Env::Development {
49-
// Print a log for each request.
49+
// Optionally print debug information for each request
50+
// To enable, set the environment variable: `RUST_LOG=cargo_registry::middleware=debug`
5051
m.add(Debug);
5152
}
5253

src/middleware/debug.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ impl Middleware for Debug {
1212

1313
fn after(&self, _req: &mut dyn RequestExt, res: AfterResult) -> AfterResult {
1414
res.map(|res| {
15-
println!(" <- {:?}", res.status());
15+
debug!(" <- {:?}", res.status());
1616
for (k, v) in res.headers().iter() {
17-
println!(" <- {} {:?}", k, v);
17+
debug!(" <- {} {:?}", k, v);
1818
}
1919
res
2020
})
@@ -26,15 +26,15 @@ struct DebugRequest;
2626

2727
impl Middleware for DebugRequest {
2828
fn before(&self, req: &mut dyn RequestExt) -> BeforeResult {
29-
println!(" version: {:?}", req.http_version());
30-
println!(" method: {:?}", req.method());
31-
println!(" scheme: {:?}", req.scheme());
32-
println!(" host: {:?}", req.host());
33-
println!(" path: {}", req.path());
34-
println!(" query_string: {:?}", req.query_string());
35-
println!(" remote_addr: {:?}", req.remote_addr());
29+
debug!(" version: {:?}", req.http_version());
30+
debug!(" method: {:?}", req.method());
31+
debug!(" scheme: {:?}", req.scheme());
32+
debug!(" host: {:?}", req.host());
33+
debug!(" path: {}", req.path());
34+
debug!(" query_string: {:?}", req.query_string());
35+
debug!(" remote_addr: {:?}", req.remote_addr());
3636
for (k, ref v) in req.headers().iter() {
37-
println!(" hdr: {}={:?}", k, v);
37+
debug!(" hdr: {}={:?}", k, v);
3838
}
3939
Ok(())
4040
}

0 commit comments

Comments
 (0)