Skip to content

Commit 6aae278

Browse files
authored
Remove log.log_http_headers config and move log calls into submodules (#1309)
This rather ad-hoc random config option was weird. Now two noisy log messages can be individually filtered by moving them to separate submodules. This changes the default when just setting `filters.tobira = "trace`" in that now, HTTP headers are also printed. But I think that's totally fine. Fixes #1291
2 parents 3bd3e91 + 088d753 commit 6aae278

File tree

6 files changed

+47
-24
lines changed

6 files changed

+47
-24
lines changed

backend/src/http/handlers.rs

+2-13
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,8 @@ use super::{Context, Response, response};
3030
/// This is the main HTTP entry point, called for each incoming request.
3131
pub(super) async fn handle(req: Request<Incoming>, ctx: Arc<Context>) -> Response {
3232
let time_incoming = Instant::now();
33-
trace!(
34-
method = ?req.method(),
35-
path = req.uri().path_and_query().map_or("", |pq| pq.as_str()),
36-
"Incoming HTTP request",
37-
);
38-
if ctx.config.log.log_http_headers {
39-
let mut out = String::new();
40-
for (name, value) in req.headers() {
41-
use std::fmt::Write;
42-
write!(out, "\n {}: {}", name, String::from_utf8_lossy(value.as_bytes())).unwrap();
43-
}
44-
trace!("HTTP Headers: {}", out);
45-
}
33+
super::log::req::log(&req);
34+
super::log::headers::log(&req);
4635

4736
let method = req.method().clone();
4837
let path = req.uri().path().trim_end_matches('/');

backend/src/http/log.rs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//! This module contains a bunch of small inline modules to make it possible to
2+
//! easily filter out individual log messages with out filter system.
3+
4+
5+
use hyper::{body::Incoming, Request};
6+
use crate::prelude::*;
7+
8+
pub mod req {
9+
use super::*;
10+
11+
pub fn log(req: &Request<Incoming>) {
12+
trace!(
13+
method = ?req.method(),
14+
path = req.uri().path_and_query().map_or("", |pq| pq.as_str()),
15+
"Incoming HTTP request",
16+
);
17+
}
18+
}
19+
20+
21+
22+
pub mod headers {
23+
use super::*;
24+
25+
pub fn log(req: &Request<Incoming>) {
26+
if tracing::enabled!(tracing::Level::TRACE) {
27+
let mut out = String::new();
28+
for (name, value) in req.headers() {
29+
use std::fmt::Write;
30+
write!(out, "\n {}: {}", name, String::from_utf8_lossy(value.as_bytes())).unwrap();
31+
}
32+
trace!("HTTP Headers: {}", out);
33+
}
34+
}
35+
}

backend/src/http/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use self::{
3838

3939
mod assets;
4040
mod handlers;
41+
mod log;
4142
pub(crate) mod response;
4243

4344

backend/src/logger.rs

-5
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ pub(crate) struct LogConfig {
5252
/// If this is set to `false`, log messages are not written to stdout.
5353
#[config(default = true)]
5454
pub(crate) stdout: bool,
55-
56-
/// If set to `true`, HTTP header of each incoming request are logged
57-
/// (with 'trace' level).
58-
#[config(default = false)]
59-
pub(crate) log_http_headers: bool,
6055
}
6156

6257
#[derive(Debug, Deserialize)]

docs/docs/setup/auth/user/index.md

+9
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ Tobira only gets new data about a user at login, and it's impossible to implemen
4040
If you can't use the built-in session management, use `"callback:..."`, which gives you full flexibility.
4141
`"trust-auth-headers"` should be avoided as it has some disadvantages compared to `"callback:..."` (header length limits, easier to configure, ...), but you can still use it if it works well within your system.
4242

43+
:::tip
44+
45+
For debugging your integration, configure the following log filter:
46+
47+
```toml
48+
[log]
49+
filters."tobira::http" = "trace"
50+
```
51+
:::
4352

4453
## User information Tobira needs
4554

docs/docs/setup/config.toml

-6
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,6 @@
392392
# Default value: true
393393
#stdout = true
394394

395-
# If set to `true`, HTTP header of each incoming request are logged
396-
# (with 'trace' level).
397-
#
398-
# Default value: false
399-
#log_http_headers = false
400-
401395

402396
[opencast]
403397
# URL to Opencast. Currently used for all purposes (syncing, Studio,

0 commit comments

Comments
 (0)