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