Skip to content

Commit

Permalink
Disable env-filter feature in tracing-subscriber
Browse files Browse the repository at this point in the history
Replaced by Targets, which is similar but simpler. This eliminates a second copy of regex-automata and regex-syntax, which eliminates ~5s from the build time.
  • Loading branch information
LucasPickering committed Jul 28, 2024
1 parent 3bb3c4a commit 28151ad
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 34 deletions.
34 changes: 3 additions & 31 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ slumber_core = {path = "./crates/slumber_core", version = "1.7.0"}
slumber_tui = {path = "./crates/slumber_tui", version = "1.7.0"}
tokio = {workspace = true, features = ["macros", "rt-multi-thread"]}
tracing = {workspace = true}
tracing-subscriber = {version = "0.3.17", default-features = false, features = ["ansi", "env-filter", "fmt", "registry"]}
tracing-subscriber = {version = "0.3.17", default-features = false, features = ["ansi", "fmt", "registry"]}

# The profile that 'cargo dist' will build with
[profile.dist]
Expand Down
10 changes: 8 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use slumber_core::util::{DataDirectory, TempDirectory};
use slumber_tui::Tui;
use std::{fs::File, io, process::ExitCode};
use tracing::level_filters::LevelFilter;
use tracing_subscriber::{filter::EnvFilter, fmt::format::FmtSpan, prelude::*};
use tracing_subscriber::{filter::Targets, fmt::format::FmtSpan, prelude::*};

#[tokio::main]
async fn main() -> anyhow::Result<ExitCode> {
Expand Down Expand Up @@ -51,14 +51,20 @@ async fn main() -> anyhow::Result<ExitCode> {
fn initialize_tracing(console_output: bool) -> anyhow::Result<()> {
let path = TempDirectory::get().log();
let log_file = File::create(path)?;
// Basically a minimal version of EnvFilter that doesn't require regexes
// https://github.com/tokio-rs/tracing/issues/1436#issuecomment-918528013
let targets: Targets = std::env::var("RUST_LOG")
.ok()
.and_then(|env| env.parse().ok())
.unwrap_or_default();
let file_subscriber = tracing_subscriber::fmt::layer()
.with_file(true)
.with_line_number(true)
.with_writer(log_file)
.with_target(false)
.with_ansi(false)
.with_span_events(FmtSpan::NEW)
.with_filter(EnvFilter::from_default_env());
.with_filter(targets);

// Enable console output for CLI
let console_subscriber = if console_output {
Expand Down

0 comments on commit 28151ad

Please sign in to comment.