From d29330466726ae7263598fd8051894e18745461b Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Wed, 14 Feb 2024 08:56:31 +0700 Subject: feat(tvix/cli): set up tracing[-subscriber] No otlp yet, this simply gives us structured log output and a cli argument for the log level. Change-Id: Ifaa60bae419640e92baebb6ee59eedd775c769c2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10853 Reviewed-by: raitobezarius Tested-by: BuildkiteCI Autosubmit: flokli --- tvix/Cargo.lock | 1 + tvix/Cargo.nix | 5 +++++ tvix/cli/Cargo.toml | 3 ++- tvix/cli/src/main.rs | 18 ++++++++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) (limited to 'tvix') diff --git a/tvix/Cargo.lock b/tvix/Cargo.lock index 430d369a1bee..7d3b52a3051c 100644 --- a/tvix/Cargo.lock +++ b/tvix/Cargo.lock @@ -3317,6 +3317,7 @@ dependencies = [ "thiserror", "tokio", "tracing", + "tracing-subscriber", "tvix-build", "tvix-castore", "tvix-eval", diff --git a/tvix/Cargo.nix b/tvix/Cargo.nix index 4e6c037d0f52..3e74c4776e4d 100644 --- a/tvix/Cargo.nix +++ b/tvix/Cargo.nix @@ -10380,6 +10380,11 @@ rec { name = "tracing"; packageId = "tracing"; } + { + name = "tracing-subscriber"; + packageId = "tracing-subscriber"; + features = [ "json" ]; + } { name = "tvix-build"; packageId = "tvix-build"; diff --git a/tvix/cli/Cargo.toml b/tvix/cli/Cargo.toml index f8101300b194..81e28c4c7cf0 100644 --- a/tvix/cli/Cargo.toml +++ b/tvix/cli/Cargo.toml @@ -19,8 +19,9 @@ clap = { version = "4.0", features = ["derive", "env"] } dirs = "4.0.0" rustyline = "10.0.0" thiserror = "1.0.38" -tracing = "0.1.37" tokio = "1.28.0" +tracing = "0.1.37" +tracing-subscriber = { version = "0.3.16", features = ["json"] } [dependencies.wu-manber] git = "https://github.com/tvlfyi/wu-manber.git" diff --git a/tvix/cli/src/main.rs b/tvix/cli/src/main.rs index da09ab878954..24b180c1f289 100644 --- a/tvix/cli/src/main.rs +++ b/tvix/cli/src/main.rs @@ -2,6 +2,9 @@ use clap::Parser; use rustyline::{error::ReadlineError, Editor}; 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 tvix_build::buildservice; use tvix_eval::builtins::impure_builtins; use tvix_eval::observer::{DisassemblingObserver, TracingObserver}; @@ -12,6 +15,9 @@ use tvix_glue::{builtins::add_derivation_builtins, configure_nix_path}; #[derive(Parser)] struct Args { + #[arg(long)] + log_level: Option, + /// Path to a script to evaluate script: Option, @@ -213,6 +219,18 @@ fn lint(code: &str, path: Option, 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)) + .pretty(), + ); + subscriber + .try_init() + .expect("unable to set up tracing subscriber"); + if let Some(file) = &args.script { run_file(file.clone(), &args) } else if let Some(expr) = &args.expr { -- cgit 1.4.1