Skip to content

Instantly share code, notes, and snippets.

@durka
Created December 12, 2017 21:02
Show Gist options
  • Save durka/6f98945a0713ec83df7e7e22bcc0d638 to your computer and use it in GitHub Desktop.
Save durka/6f98945a0713ec83df7e7e22bcc0d638 to your computer and use it in GitHub Desktop.
//! ```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