diff options
author | Simon Hauser <simon.hauser@helsinki-systems.de> | 2024-06-06T13·44+0200 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-06-10T16·35+0000 |
commit | 825d498908e2f6c9fdca3225afefb0aa4b3cc747 (patch) | |
tree | 765e5412bf24ae41bb3d6f42791a229b68a88451 /tvix/cli/src | |
parent | 11a6ff77067a7b9eec3f1c15412d7143cb85a047 (diff) |
feat(tvix/tracing): introduce common tvix-tracing crate r/8242
Introduce a new common crate that contains tracing boilerplate which then can be used in the cli, tvix-store and tvix-build crates. It has otlp as an optional feature, which is currently only used by tvix-store. Change-Id: I41468ac4d9c65174515d721513b96fea463d6ed2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11758 Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de> Autosubmit: Simon Hauser <simon.hauser@helsinki-systems.de>
Diffstat (limited to 'tvix/cli/src')
-rw-r--r-- | tvix/cli/src/main.rs | 30 |
1 files changed, 7 insertions, 23 deletions
diff --git a/tvix/cli/src/main.rs b/tvix/cli/src/main.rs index 66ec5a99dba6..bb0b9b768b02 100644 --- a/tvix/cli/src/main.rs +++ b/tvix/cli/src/main.rs @@ -5,9 +5,6 @@ use repl::Repl; use std::rc::Rc; use std::{fs, path::PathBuf}; use tracing::Level; -use tracing_subscriber::fmt::writer::MakeWriterExt; -use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; -use tracing_subscriber::{EnvFilter, Layer}; use tvix_build::buildservice; use tvix_eval::builtins::impure_builtins; use tvix_eval::observer::{DisassemblingObserver, TracingObserver}; @@ -27,8 +24,12 @@ static GLOBAL: Jemalloc = Jemalloc; #[derive(Parser, Clone)] struct Args { - #[arg(long)] - log_level: Option<Level>, + /// A global log level to use when printing logs. + /// It's also possible to set `RUST_LOG` according to + /// `tracing_subscriber::filter::EnvFilter`, which will always have + /// priority. + #[arg(long, default_value_t=Level::INFO)] + log_level: Level, /// Path to a script to evaluate script: Option<PathBuf>, @@ -270,24 +271,7 @@ fn lint(code: &str, path: Option<PathBuf>, args: &Args) -> bool { fn main() { let args = Args::parse(); - // configure log settings - let level = args.log_level.unwrap_or(Level::INFO); - - let subscriber = tracing_subscriber::registry().with( - tracing_subscriber::fmt::Layer::new() - .with_writer(std::io::stderr.with_max_level(level)) - .compact() - .with_filter( - EnvFilter::builder() - .with_default_directive(level.into()) - .from_env() - .expect("invalid RUST_LOG"), - ), - ); - subscriber - .try_init() - .expect("unable to set up tracing subscriber"); - + tvix_tracing::init(args.log_level).expect("unable to set up tracing subscriber"); let tokio_runtime = tokio::runtime::Runtime::new().expect("failed to setup tokio runtime"); let io_handle = init_io_handle(&tokio_runtime, &args); |