about summary refs log tree commit diff
path: root/users/picnoir/tvix-daemon/src/main.rs
diff options
context:
space:
mode:
authorPicnoir <picnoir@alternativebit.fr>2024-04-03T09·20+0200
committerpicnoir picnoir <picnoir@alternativebit.fr>2024-04-03T11·32+0000
commit32724d28eeb7eb5f9e695993e792e79ba61be933 (patch)
tree89ba4767a91f15bbfac1ba146926c98521554e45 /users/picnoir/tvix-daemon/src/main.rs
parent9cec50cb2eb1606511d8e8d3e8a4137e0feb6ffa (diff)
feat(users/picnoir/tvix-daemon): add log verbosity flag r/7847
Adding a verbosity flag available through the CLI/ENV variable.

Change-Id: If04cc2e6e26e7cb3c2df7821fce222da2b85a95a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11349
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Diffstat (limited to 'users/picnoir/tvix-daemon/src/main.rs')
-rw-r--r--users/picnoir/tvix-daemon/src/main.rs15
1 files changed, 12 insertions, 3 deletions
diff --git a/users/picnoir/tvix-daemon/src/main.rs b/users/picnoir/tvix-daemon/src/main.rs
index e302b83fcbf9..7b1b735baa8c 100644
--- a/users/picnoir/tvix-daemon/src/main.rs
+++ b/users/picnoir/tvix-daemon/src/main.rs
@@ -2,7 +2,7 @@ use anyhow::anyhow;
 use clap::Parser;
 use tokio::io::{AsyncReadExt, AsyncWriteExt};
 use tokio_listener::{self, SystemOptions, UserOptions};
-use tracing::{debug, error, info, instrument};
+use tracing::{debug, error, info, instrument, Level};
 
 use nix_compat::wire::{bytes, primitive, worker_protocol};
 
@@ -11,14 +11,23 @@ struct Cli {
     /// Listening unix socket path
     #[arg(short, long)]
     socket: Option<String>,
+    /// Log verbosity level. Can be "error", "warn", "info", "debug", "trace", or a number 1-5
+    #[arg(short, long, env)]
+    verbosity: Option<Level>,
 }
 
 #[tokio::main]
 #[instrument()]
 async fn main() {
-    tracing_subscriber::fmt().compact().try_init().unwrap();
     let args = Cli::parse();
-
+    tracing_subscriber::fmt()
+        .compact()
+        .with_max_level(
+            args.verbosity
+                .unwrap_or_else(|| panic!("Can't parse log verbosity")),
+        )
+        .try_init()
+        .unwrap();
     info!("Started Tvix daemon");
     let addr = args
         .socket