-
Notifications
You must be signed in to change notification settings - Fork 5
/
logging.rs
44 lines (39 loc) · 1.42 KB
/
logging.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//! Logging setup for the server and client
#[cfg(feature = "ssr")]
use tower_http::{
classify::{ServerErrorsAsFailures, SharedClassifier},
trace::TraceLayer,
};
/// Setup server-side logging using [tracing_subscriber]
#[cfg(feature = "ssr")]
pub fn setup_server_logging() {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO) // TODO: --verbose should use DEBUG
.compact()
.init();
}
/// Setup browser console logging using [tracing_subscriber_wasm]
#[cfg(feature = "hydrate")]
pub fn setup_client_logging() {
tracing_subscriber::fmt()
.with_writer(
// To avoide trace events in the browser from showing their
// JS backtrace, which is very annoying, in my opinion
tracing_subscriber_wasm::MakeConsoleWriter::default()
.map_trace_level_to(tracing::Level::DEBUG),
)
.with_max_level(tracing::Level::INFO)
// For some reason, if we don't do this in the browser, we get
// a runtime error.
.without_time()
.init();
}
/// Setup HTTP request logging
#[cfg(feature = "ssr")]
pub fn http_trace_layer() -> TraceLayer<SharedClassifier<ServerErrorsAsFailures>> {
use tower_http::trace;
use tracing::Level;
TraceLayer::new_for_http()
.make_span_with(trace::DefaultMakeSpan::new().level(Level::DEBUG))
.on_response(trace::DefaultOnResponse::new().level(Level::DEBUG))
}