|
12 | 12 | // See the License for the specific language governing permissions and |
13 | 13 | // limitations under the License. |
14 | 14 |
|
| 15 | +use std::env; |
15 | 16 | use std::net::Ipv4Addr; |
16 | 17 | use std::path::PathBuf; |
17 | 18 |
|
@@ -66,13 +67,28 @@ impl Cli { |
66 | 67 | } |
67 | 68 | pub fn log_level(&self) -> Option<Level> { |
68 | 69 | use clap_verbosity_flag::Level as ClapLevel; |
69 | | - self.verbose.log_level().map(|lvl| match lvl { |
70 | | - ClapLevel::Error => Level::ERROR, |
71 | | - ClapLevel::Warn => Level::WARN, |
72 | | - ClapLevel::Info => Level::INFO, |
73 | | - ClapLevel::Debug => Level::DEBUG, |
74 | | - ClapLevel::Trace => Level::TRACE, |
75 | | - }) |
| 70 | + match self.verbose.log_level() { |
| 71 | + Some(lvl) => Some(match lvl { |
| 72 | + ClapLevel::Error => Level::ERROR, |
| 73 | + ClapLevel::Warn => Level::WARN, |
| 74 | + ClapLevel::Info => Level::INFO, |
| 75 | + ClapLevel::Debug => Level::DEBUG, |
| 76 | + ClapLevel::Trace => Level::TRACE, |
| 77 | + }), |
| 78 | + None => Some( |
| 79 | + match env::var("NUMTRACKER_LOG_LEVEL") |
| 80 | + .map(|lvl| lvl.to_ascii_lowercase()) |
| 81 | + .as_deref() |
| 82 | + { |
| 83 | + Ok("info") => Level::INFO, |
| 84 | + Ok("debug") => Level::DEBUG, |
| 85 | + Ok("trace") => Level::TRACE, |
| 86 | + Ok("warn") => Level::WARN, |
| 87 | + Ok("error") => Level::ERROR, |
| 88 | + _ => return None, |
| 89 | + }, |
| 90 | + ), |
| 91 | + } |
76 | 92 | } |
77 | 93 | pub fn tracing(&self) -> &TracingOptions { |
78 | 94 | &self.tracing |
|
0 commit comments