Skip to content

Commit

Permalink
feat: support tokio-console (#40)
Browse files Browse the repository at this point in the history
* feat: support `tokio-console`

* chore: rename feature to `tokio-console`
  • Loading branch information
kwaa committed May 26, 2024
1 parent 28dadc6 commit 68e7520
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 12 deletions.
13 changes: 10 additions & 3 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ lld = true
# [target.x86_64-unknown-linux-gnu]
# rustflags = ["-C", "linker=clang", "-C", "link-arg=-fuse-ld=lld"]

# Enable UUID Unstable Features
# https://docs.rs/uuid/1.4.0/uuid/index.html#unstable-features
[target.'cfg(all())']
rustflags = ["--cfg", "uuid_unstable"]
rustflags = [
# UUID Unstable for Uuid::now_v7()
# https://docs.rs/uuid/1.4.0/uuid/index.html#unstable-features
"--cfg",
"uuid_unstable",
# Tokio Unstable for `console` feature
# https://github.com/tokio-rs/console#instrumenting-your-program
"--cfg",
"tokio_unstable",
]

# x86_64-v3 (Intel Haswell / AMD Excavator and above)
# https://en.wikipedia.org/wiki/X86-64#Microarchitecture_levels
Expand Down
165 changes: 159 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ opt-level = "z"
panic = "abort"
strip = "symbols"

[features]
default = ["tokio-console"]
tokio-console = ["dep:console-subscriber", "tokio/tracing"]

[workspace]
members = [
".",
Expand Down Expand Up @@ -134,3 +138,6 @@ tokio-graceful-shutdown = { workspace = true }
tracing = { workspace = true }
tracing-error = { workspace = true }
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }

# optional-dependencies
console-subscriber = { version = "0.2", optional = true }
10 changes: 7 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ use tracing_subscriber::prelude::*;
async fn main() -> Result<(), AppError> {
setup_panic!(metadata!().homepage("https://github.com/importantimport/hatsu/issues"));

tracing_subscriber::registry()
let registry = tracing_subscriber::registry()
.with(tracing_subscriber::fmt::layer())
.with(tracing_error::ErrorLayer::default())
.init();
.with(tracing_error::ErrorLayer::default());

#[cfg(feature = "tokio-console")]
let registry = registry.with(console_subscriber::spawn());

registry.init();

tracing::info!("loading environment variables");
if dotenvy::dotenv().is_err() {
Expand Down

0 comments on commit 68e7520

Please sign in to comment.