Skip to main content

systemprompt_models/config/
verbosity.rs

1//! Verbosity level configuration.
2
3use super::Environment;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum VerbosityLevel {
7    Quiet,
8    Normal,
9    Verbose,
10    Debug,
11}
12
13impl VerbosityLevel {
14    pub const fn from_environment(env: Environment) -> Self {
15        match env {
16            Environment::Development => Self::Verbose,
17            Environment::Production => Self::Quiet,
18            Environment::Test => Self::Normal,
19        }
20    }
21
22    pub fn from_env_var() -> Option<Self> {
23        if std::env::var("SYSTEMPROMPT_QUIET").ok().as_deref() == Some("1") {
24            return Some(Self::Quiet);
25        }
26
27        if std::env::var("SYSTEMPROMPT_VERBOSE").ok().as_deref() == Some("1") {
28            return Some(Self::Verbose);
29        }
30
31        if std::env::var("SYSTEMPROMPT_DEBUG").ok().as_deref() == Some("1") {
32            return Some(Self::Debug);
33        }
34
35        if let Ok(level) = std::env::var("SYSTEMPROMPT_LOG_LEVEL") {
36            return match level.to_lowercase().as_str() {
37                "quiet" => Some(Self::Quiet),
38                "normal" => Some(Self::Normal),
39                "verbose" => Some(Self::Verbose),
40                "debug" => Some(Self::Debug),
41                _ => None,
42            };
43        }
44
45        None
46    }
47
48    pub fn resolve() -> Self {
49        if let Some(level) = Self::from_env_var() {
50            return level;
51        }
52
53        let env = Environment::detect();
54        Self::from_environment(env)
55    }
56
57    pub const fn is_quiet(&self) -> bool {
58        matches!(self, Self::Quiet)
59    }
60
61    pub const fn is_verbose(&self) -> bool {
62        matches!(self, Self::Verbose | Self::Debug)
63    }
64
65    pub const fn should_show_verbose(&self) -> bool {
66        matches!(self, Self::Verbose | Self::Debug)
67    }
68
69    pub const fn should_log_to_db(&self) -> bool {
70        !matches!(self, Self::Quiet)
71    }
72}