Skip to content

Commit 5bec086

Browse files
committed
feat: add structured logging with tracing and env-filter
Initialize tracing-subscriber with RUST_LOG env filter, --verbose maps to debug level. Add debug instrumentation to config load, symbol extraction, context building, and provider verification. Respects NO_COLOR for ANSI output control.
1 parent bcf3438 commit 5bec086

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

src/app.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::io::IsTerminal;
88
use tokio::signal;
99
use tokio::sync::mpsc;
1010
use tokio_util::sync::CancellationToken;
11+
use tracing::{debug, warn};
1112

1213
use crate::cli::{Cli, Commands};
1314
use crate::config::Config;
@@ -26,6 +27,12 @@ pub struct App {
2627
impl App {
2728
pub fn new(cli: Cli) -> Result<Self> {
2829
let config = Config::load(&cli)?;
30+
debug!(
31+
provider = %config.provider,
32+
model = %config.model,
33+
max_diff_lines = config.max_diff_lines,
34+
"config loaded"
35+
);
2936
let cancel_token = CancellationToken::new();
3037
Ok(Self {
3138
cli,
@@ -75,6 +82,10 @@ impl App {
7582

7683
let secrets = safety::scan_for_secrets(&changes);
7784
if !secrets.is_empty() && !self.cli.allow_secrets {
85+
warn!(
86+
count = secrets.len(),
87+
"potential secrets detected in staged changes"
88+
);
7889
self.print_warning("Potential secrets detected:");
7990
for s in &secrets {
8091
eprintln!(
@@ -109,12 +120,11 @@ impl App {
109120
&|path| git_ref.get_head_content(path),
110121
);
111122

112-
if self.cli.verbose && !symbols.is_empty() {
113-
eprintln!("{} Found {} symbols", style("info:").cyan(), symbols.len());
114-
}
123+
debug!(count = symbols.len(), "symbols extracted");
115124

116125
// Step 4: Build context
117126
let context = ContextBuilder::build(&changes, &symbols, &self.config);
127+
debug!(prompt_chars = context.to_prompt().len(), "context built");
118128

119129
let prompt = context.to_prompt();
120130

@@ -135,6 +145,7 @@ impl App {
135145
));
136146

137147
let provider = llm::create_provider(&self.config)?;
148+
debug!(provider = provider.name(), "verifying provider");
138149
provider.verify().await?;
139150

140151
// Setup streaming output
@@ -175,6 +186,7 @@ impl App {
175186
}
176187

177188
// Step 6: Sanitize and validate the commit message
189+
debug!(raw_len = raw_message.len(), "sanitizing LLM response");
178190
let message = CommitSanitizer::sanitize(&raw_message, &self.config.format)?;
179191

180192
// Step 7: Confirm and commit

src/main.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: GPL-3.0-only
44

55
use clap::Parser;
6+
use tracing_subscriber::EnvFilter;
67

78
mod app;
89
mod cli;
@@ -28,6 +29,20 @@ async fn main() {
2829

2930
let cli = Cli::parse();
3031

32+
let filter = if cli.verbose {
33+
EnvFilter::new("commitbee=debug")
34+
} else {
35+
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("commitbee=warn"))
36+
};
37+
38+
tracing_subscriber::fmt()
39+
.with_env_filter(filter)
40+
.with_writer(std::io::stderr)
41+
.with_target(false)
42+
.with_ansi(std::env::var("NO_COLOR").is_err())
43+
.without_time()
44+
.init();
45+
3146
let mut app = match App::new(cli) {
3247
Ok(app) => app,
3348
Err(e) => {

0 commit comments

Comments
 (0)