Skip to content

Commit 4e7a8b9

Browse files
authored
svix-cli: add tracing support (#2114)
This is helpful for debugging. Rather than use the `RUST_LOG` env var, I've used the standard Unix `-v` / `--verbose` flags.
1 parent fe300b4 commit 4e7a8b9

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

svix-cli/Cargo.lock

Lines changed: 83 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

svix-cli/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ serde_json = "1.0.133"
5252
svix = { path = "../rust" }
5353
tokio = { version = "1.42.0", features = ["macros", "time", "rt-multi-thread"] }
5454
tokio-tungstenite = { version = "0.26.0", features = ["rustls-tls-native-roots"] }
55+
tracing = "0.1"
56+
tracing-subscriber = { version = "0.3", features=["std", "ansi", "fmt", "registry", "local-time"], default-features = false }
5557
toml = "0.8.19"
5658
url = "2.5.4"
5759

svix-cli/src/main.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ const BIN_NAME: &str = env!("CARGO_BIN_NAME");
3737
struct Cli {
3838
#[command(flatten)]
3939
color: Color,
40+
#[arg(
41+
short,
42+
long,
43+
action = clap::ArgAction::Count,
44+
help = "Log more. This option may be repeated up to 3 times"
45+
)]
46+
verbose: u8,
4047
#[command(subcommand)]
4148
command: RootCommands,
4249
}
@@ -53,6 +60,15 @@ impl Cli {
5360
ColorChoice::Never => ColorMode::Off,
5461
}
5562
}
63+
64+
fn log_level(&self) -> tracing::Level {
65+
match self.verbose {
66+
3.. => tracing::Level::TRACE,
67+
2 => tracing::Level::DEBUG,
68+
1 => tracing::Level::INFO,
69+
0 => tracing::Level::WARN,
70+
}
71+
}
5672
}
5773

5874
// N.b Ordering matters here for how clap presents the help.
@@ -103,6 +119,11 @@ async fn main() -> Result<()> {
103119
let cli = Cli::parse();
104120
let color_mode = cli.color_mode();
105121

122+
tracing_subscriber::fmt()
123+
.with_max_level(cli.log_level())
124+
.with_timer(tracing_subscriber::fmt::time::LocalTime::rfc_3339())
125+
.init();
126+
106127
// rustls requires a crypto backend ("provider") choice to be made explicitly
107128
// The Svix SDK uses the default provider if a default is not installed, but
108129
// we use reqwest directly in some code paths, which does not do this.

0 commit comments

Comments
 (0)