Skip to content

Commit 02a4fb7

Browse files
committed
feat: add ability to override tracing level
1 parent b448538 commit 02a4fb7

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ pub mod graphql;
134134
#[cfg(feature = "graphiql")]
135135
#[cfg_attr(docsrs, doc(cfg(feature = "graphiql")))]
136136
pub mod graphiql;
137+
137138
pub use bytes::Bytes;
138139
pub use http::{Method, StatusCode, header};
139140
pub use http_body_util::Full;
@@ -166,11 +167,9 @@ pub use server::serve;
166167
/// This helper is primarily intended for local development and example binaries.
167168
/// It will keep proposing the next port number until a free one is found or
168169
/// the user declines.
169-
pub async fn bind_with_port_fallback(
170-
addr: &str,
171-
) -> io::Result<tokio::net::TcpListener> {
172-
let mut socket_addr = SocketAddr::from_str(addr)
173-
.map_err(|e| io::Error::new(ErrorKind::InvalidInput, e))?;
170+
pub async fn bind_with_port_fallback(addr: &str) -> io::Result<tokio::net::TcpListener> {
171+
let mut socket_addr =
172+
SocketAddr::from_str(addr).map_err(|e| io::Error::new(ErrorKind::InvalidInput, e))?;
174173
let start_port = socket_addr.port();
175174

176175
loop {

src/tracing.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@
55
//! log levels, and span events. The tracing system helps with debugging, monitoring,
66
//! and understanding application behavior in development and production environments.
77
8-
use tracing::level_filters::LevelFilter;
98
use tracing_subscriber::{
109
Layer, fmt::format::FmtSpan, layer::SubscriberExt, util::SubscriberInitExt,
1110
};
1211

12+
pub use tracing::level_filters::LevelFilter;
13+
14+
pub static mut TRACING_LEVEL: LevelFilter = LevelFilter::DEBUG;
15+
16+
pub fn set_tracing_level(level_filter: LevelFilter) {
17+
unsafe { TRACING_LEVEL = level_filter };
18+
}
19+
1320
/// Initializes the global tracing subscriber with formatted output.
1421
pub fn init_tracing() {
1522
tracing_subscriber::registry()
@@ -19,7 +26,7 @@ pub fn init_tracing() {
1926
.with_file(true)
2027
.with_line_number(true)
2128
.with_level(true)
22-
.with_filter(LevelFilter::DEBUG),
29+
.with_filter(unsafe { TRACING_LEVEL }),
2330
)
2431
.init();
2532
}

0 commit comments

Comments
 (0)