Skip to main content

systemprompt_cli/commands/infrastructure/logs/
shared.rs

1//! Formatting helpers shared across the `infra logs` subcommands.
2//!
3//! Re-exports the timestamp/duration formatters from `systemprompt_models` and
4//! provides [`display_log_row`] and [`cost_microdollars_to_dollars`] used by
5//! the view, search, and trace renderers.
6
7use systemprompt_logging::CliService;
8use systemprompt_models::text::truncate_with_ellipsis;
9
10use super::LogEntryRow;
11
12pub use systemprompt_models::time_format::{format_optional_duration_ms, format_timestamp};
13
14pub fn cost_microdollars_to_dollars(microdollars: i64) -> f64 {
15    microdollars as f64 / 1_000_000.0
16}
17
18pub fn display_log_row(log: &LogEntryRow) {
19    let time_part = if log.timestamp.len() >= 23 {
20        &log.timestamp[11..23]
21    } else {
22        &log.timestamp
23    };
24
25    let trace_short = truncate_with_ellipsis(log.trace_id.as_str(), 8);
26
27    let line = format!(
28        "{} {} [{}] {}  [{}]",
29        time_part, log.level, log.module, log.message, trace_short
30    );
31
32    match log.level.as_str() {
33        "ERROR" => CliService::error(&line),
34        "WARN" => CliService::warning(&line),
35        _ => CliService::info(&line),
36    }
37}