mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-10-10 03:30:59 +00:00
Separate serve logs from CLI logs
`arc serve` writes to `serve-YYYY-MM-DD.log` and all other commands write to `cli-YYYY-MM-DD.log` so the two are easy to tail independently. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
9b7f18d112
commit
7836eb4eaa
2 changed files with 10 additions and 6 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use anyhow::{Context, Result};
|
||||
use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
|
||||
|
||||
pub fn init_tracing(debug: bool) -> Result<()> {
|
||||
pub fn init_tracing(debug: bool, log_prefix: &str) -> Result<()> {
|
||||
let default_level = if debug { "debug" } else { "info" };
|
||||
let filter =
|
||||
EnvFilter::try_from_env("ARC_LOG").unwrap_or_else(|_| EnvFilter::new(default_level));
|
||||
|
|
@ -13,7 +13,9 @@ pub fn init_tracing(debug: bool) -> Result<()> {
|
|||
std::fs::create_dir_all(&log_dir)
|
||||
.with_context(|| format!("Failed to create log directory: {}", log_dir.display()))?;
|
||||
|
||||
let filename = chrono::Local::now().format("%Y-%m-%d.log").to_string();
|
||||
let filename = chrono::Local::now()
|
||||
.format(&format!("{log_prefix}-%Y-%m-%d.log"))
|
||||
.to_string();
|
||||
let file_appender = tracing_appender::rolling::never(&log_dir, &filename);
|
||||
|
||||
tracing_subscriber::registry()
|
||||
|
|
|
|||
|
|
@ -125,10 +125,6 @@ async fn main() -> Result<()> {
|
|||
dotenvy::dotenv().ok();
|
||||
}
|
||||
|
||||
if let Err(err) = logging::init_tracing(cli.debug) {
|
||||
eprintln!("Warning: failed to initialize logging: {err:#}");
|
||||
}
|
||||
|
||||
let command_name = match &cli.command {
|
||||
Command::Llm { .. } => "llm",
|
||||
Command::Agent(_) => "agent",
|
||||
|
|
@ -140,6 +136,12 @@ async fn main() -> Result<()> {
|
|||
Command::Doctor { .. } => "doctor",
|
||||
Command::Setup => "setup",
|
||||
};
|
||||
|
||||
let log_prefix = if command_name == "serve" { "serve" } else { "cli" };
|
||||
if let Err(err) = logging::init_tracing(cli.debug, log_prefix) {
|
||||
eprintln!("Warning: failed to initialize logging: {err:#}");
|
||||
}
|
||||
|
||||
debug!(command = %command_name, "CLI command started");
|
||||
|
||||
match cli.command {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue