프로젝트 이름 `kb` → `kebab` rename 의 첫 단계. - workspace `Cargo.toml`: members `crates/kb-*` → `crates/kebab-*`, repository URL `altair823/kb` → `altair823/kebab`. - 18 crate 폴더 rename via `git mv` (history 보존). - 각 crate `Cargo.toml`: `name = "kb-*"` → `"kebab-*"`, path deps `../kb-*` → `../kebab-*`. - 모든 `.rs`: `kb_<id>` snake-case 모듈 path 18 개 (`kb_core`, `kb_config`, `kb_app`, `kb_cli`, `kb_eval`, `kb_search`, `kb_chunk`, `kb_normalize`, `kb_source_fs`, `kb_parse_md`, `kb_parse_types`, `kb_store_sqlite`, `kb_store_vector`, `kb_embed`, `kb_embed_local`, `kb_llm`, `kb_llm_local`, `kb_rag`) → `kebab_<id>` 일괄 sed (단어 경계 \\b 사용해 영어 문장 안의 "kb" 약어 미오염). CLI binary 이름 (`[[bin]] name = "kb"`), 환경변수 `KB_*`, XDG paths, tracing target, 그리고 docs sweep 은 다음 commit 에서. ## 검증 - `cargo check --workspace` clean — 모든 crate 빌드 통과 후 commit. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
44 lines
1.5 KiB
Rust
44 lines
1.5 KiB
Rust
//! Tracing initialization helper for `kb-cli`.
|
|
//!
|
|
//! Daily-rolling file appender at `~/.local/state/kb/logs/` per task spec.
|
|
//! Returns a `WorkerGuard` that the caller must keep alive until program
|
|
//! exit (so buffered log lines flush).
|
|
|
|
use anyhow::Result;
|
|
use tracing_appender::non_blocking::WorkerGuard;
|
|
use tracing_subscriber::{EnvFilter, fmt, prelude::*};
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
pub enum LogLevel {
|
|
Default,
|
|
Verbose,
|
|
Debug,
|
|
}
|
|
|
|
/// Initialize tracing. Returns a guard to keep alive until exit. Idempotent
|
|
/// — a second call is a no-op (the second `try_init` is dropped silently
|
|
/// but the guard is still returned so the caller can keep it alive).
|
|
pub fn init(level: LogLevel) -> Result<WorkerGuard> {
|
|
let log_dir = kebab_config::Config::xdg_state_dir().join("logs");
|
|
std::fs::create_dir_all(&log_dir)?;
|
|
|
|
let file_appender = tracing_appender::rolling::daily(&log_dir, "kb.log");
|
|
let (nb, guard) = tracing_appender::non_blocking(file_appender);
|
|
|
|
let env_filter = match level {
|
|
LogLevel::Default => EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("warn")),
|
|
LogLevel::Verbose => EnvFilter::new("info"),
|
|
LogLevel::Debug => EnvFilter::new("debug"),
|
|
};
|
|
|
|
let registry = tracing_subscriber::registry()
|
|
.with(env_filter)
|
|
.with(fmt::layer().with_writer(nb).with_ansi(false));
|
|
|
|
// `try_init` rather than `init` so a second call (e.g. in tests) is a
|
|
// no-op.
|
|
let _ = registry.try_init();
|
|
|
|
Ok(guard)
|
|
}
|