Created
December 12, 2017 21:02
-
-
Save durka/6f98945a0713ec83df7e7e22bcc0d638 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //! ```cargo | |
| //! [dependencies] | |
| //! failure = "*" | |
| //! ``` | |
| extern crate failure; | |
| use failure::Error; | |
| use failure::Fail; | |
| use failure::ResultExt; | |
| use std::env::{self, VarError}; | |
| fn logging() -> Result<(), Error> { | |
| let log_level = match env::var("LOG_LEVEL") { | |
| Ok(s) => s, | |
| Err(VarError::NotPresent) => "".to_owned(), | |
| e @ Err(VarError::NotUnicode(_)) => e.context("'LOG_LEVEL' not UTF-8 compatible!")? | |
| }; | |
| println!("lvl: {}", log_level); | |
| Ok(()) | |
| } | |
| fn main() { | |
| logging().unwrap(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment