From 9441204f9fbd10646ccfc7813dc830ff4210ab7a Mon Sep 17 00:00:00 2001 From: Jacob Date: Wed, 6 May 2026 21:52:34 -0400 Subject: [PATCH] feat: make logging non-blocking --- Cargo.lock | 20 ++++++++++++++++++++ Cargo.toml | 1 + src/main.rs | 3 +++ 3 files changed, 24 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 28a3c25..327ba1a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1769,6 +1769,7 @@ dependencies = [ "tokio-websockets 0.11.4", "tokio-websockets 0.13.2", "tracing", + "tracing-appender", "tracing-subscriber", "twilight-gateway", "twilight-http", @@ -6613,6 +6614,12 @@ dependencies = [ "thiserror 2.0.17", ] +[[package]] +name = "symlink" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7973cce6668464ea31f176d85b13c7ab3bba2cb3b77a2ed26abd7801688010a" + [[package]] name = "symphonia" version = "0.5.5" @@ -7147,6 +7154,19 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "tracing-appender" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "050686193eb999b4bb3bc2acfa891a13da00f79734704c4b8b4ef1a10b368a3c" +dependencies = [ + "crossbeam-channel", + "symlink", + "thiserror 2.0.17", + "time", + "tracing-subscriber", +] + [[package]] name = "tracing-attributes" version = "0.1.31" diff --git a/Cargo.toml b/Cargo.toml index 56132da..bab59bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -95,6 +95,7 @@ twilight-model = "0.17" twilight-util = { version = "0.17", features = ["builder"] } typed-builder = "0.23.2" yoke = "0.8.2" +tracing-appender = "0.2.5" [build-dependencies] capnpc = "0.25.3" diff --git a/src/main.rs b/src/main.rs index f912b8f..53cfb7e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -173,10 +173,13 @@ async fn main() -> Result<(), MainError> { let LoggingArgs { env_filter } = logging_args; + let (non_blocking_writer, _guard) = tracing_appender::non_blocking(std::io::stdout()); + tracing_subscriber::fmt() .pretty() .with_env_filter(env_filter) .with_span_events(FmtSpan::NEW | FmtSpan::CLOSE) + .with_writer(non_blocking_writer) .init(); tracing::debug!(?app_args, "using");