Skip to main content

solverforge_console/
lib.rs

1//! Colorful console output for solver metrics.
2//!
3//! Provides a custom `tracing` layer that formats solver events with colors.
4//!
5//! ## Log Levels
6//!
7//! - **INFO**: Lifecycle events (solving/phase start/end)
8//! - **DEBUG**: Progress updates (1/sec with speed and score)
9//! - **TRACE**: Individual step evaluations
10
11mod banner;
12mod format;
13mod layer;
14mod time;
15mod visitor;
16
17pub use layer::SolverConsoleLayer;
18
19use std::sync::OnceLock;
20use tracing_subscriber::layer::SubscriberExt;
21use tracing_subscriber::util::SubscriberInitExt;
22use tracing_subscriber::EnvFilter;
23
24static INIT: OnceLock<()> = OnceLock::new();
25
26/// Initializes the solver console output.
27///
28/// Safe to call multiple times - only the first call has effect.
29/// Prints the SolverForge banner and sets up tracing.
30pub fn init() {
31    INIT.get_or_init(|| {
32        banner::print_banner();
33
34        let filter = EnvFilter::builder()
35            .with_default_directive("solverforge_solver=info".parse().unwrap())
36            .from_env_lossy()
37            .add_directive("solverforge_dynamic=info".parse().unwrap());
38
39        let _ = tracing_subscriber::registry()
40            .with(filter)
41            .with(SolverConsoleLayer)
42            .try_init();
43    });
44}