quantus_cli/
log.rs

1/*!
2 * Quantus CLI Logging Module
3 *
4 * Provides controlled output with verbose mode support
5 */
6
7use colored::Colorize;
8use std::sync::atomic::{AtomicBool, Ordering};
9
10// Global verbose flag
11static VERBOSE: AtomicBool = AtomicBool::new(false);
12
13/// Set the verbose mode for the application
14pub fn set_verbose(verbose: bool) {
15	VERBOSE.store(verbose, Ordering::Relaxed);
16}
17
18/// Check if verbose mode is enabled
19pub fn is_verbose() -> bool {
20	VERBOSE.load(Ordering::Relaxed)
21}
22
23/// Print formatted message only when verbose mode is enabled
24pub fn verboseln(args: std::fmt::Arguments) {
25	if is_verbose() {
26		println!("{args}");
27	}
28}
29
30/// Print formatted message regardless of verbose mode (for important user output)
31pub fn println(args: std::fmt::Arguments) {
32	println!("{args}");
33}
34
35/// Print formatted error message regardless of verbose mode
36pub fn errorln(args: std::fmt::Arguments) {
37	eprintln!("{} {}", "❌ Error:".red().bold(), args);
38}
39
40/// Print formatted success message regardless of verbose mode
41pub fn successln(args: std::fmt::Arguments) {
42	println!("{} {}", "✅".green(), args);
43}
44
45/// Print formatted info message in verbose mode
46pub fn infoln(args: std::fmt::Arguments) {
47	if is_verbose() {
48		println!("{} {}", "â„šī¸ ".bright_blue(), args);
49	}
50}
51
52// Macros for easier usage (similar to println! but for our logging)
53#[macro_export]
54macro_rules! log_verbose {
55    ($($arg:tt)*) => {
56        $crate::log::verboseln(format_args!($($arg)*))
57    };
58}
59
60#[macro_export]
61macro_rules! log_print {
62    () => {
63        println!()
64    };
65    ($($arg:tt)*) => {
66        $crate::log::println(format_args!($($arg)*))
67    };
68}
69
70#[macro_export]
71macro_rules! log_error {
72    ($($arg:tt)*) => {
73        $crate::log::errorln(format_args!($($arg)*))
74    };
75}
76
77#[macro_export]
78macro_rules! log_success {
79    ($($arg:tt)*) => {
80        $crate::log::successln(format_args!($($arg)*))
81    };
82}
83
84#[macro_export]
85macro_rules! log_info {
86    ($($arg:tt)*) => {
87        $crate::log::infoln(format_args!($($arg)*))
88    };
89}