Skip to content

Commit d676cc0

Browse files
committed
Load logging level from environment as well
At this stage it probably makes more sense to roll our own verbose flag instead of using the clap version.
1 parent 89bad2d commit d676cc0

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

src/cli.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use std::env;
1516
use std::net::Ipv4Addr;
1617
use std::path::PathBuf;
1718

@@ -66,13 +67,28 @@ impl Cli {
6667
}
6768
pub fn log_level(&self) -> Option<Level> {
6869
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+
}
7692
}
7793
pub fn tracing(&self) -> &TracingOptions {
7894
&self.tracing

0 commit comments

Comments
 (0)