summaryrefslogtreecommitdiffstats
path: root/lib/core/libimagrt/src/logger.rs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/core/libimagrt/src/logger.rs')
-rw-r--r--lib/core/libimagrt/src/logger.rs49
1 files changed, 17 insertions, 32 deletions
diff --git a/lib/core/libimagrt/src/logger.rs b/lib/core/libimagrt/src/logger.rs
index c79f2ec2..73c23351 100644
--- a/lib/core/libimagrt/src/logger.rs
+++ b/lib/core/libimagrt/src/logger.rs
@@ -24,10 +24,9 @@ use std::sync::Arc;
use std::sync::Mutex;
use std::ops::Deref;
-use failure::ResultExt;
-use failure::Fallible as Result;
-use failure::Error;
-use failure::err_msg;
+use anyhow::Result;
+use anyhow::Error;
+
use clap::ArgMatches;
use log::{Log, Level, Record, Metadata};
use toml::Value;
@@ -35,8 +34,6 @@ use toml_query::read::TomlValueReadExt;
use toml_query::read::TomlValueReadTypeExt;
use handlebars::Handlebars;
-use libimagerror::errors::ErrorMsg as EM;
-
#[derive(Debug)]
enum LogDestination {
Stderr,
@@ -152,7 +149,7 @@ fn match_log_level_str(s: &str) -> Result<Level> {
"info" => Ok(Level::Info),
"warn" => Ok(Level::Warn),
"error" => Ok(Level::Error),
- lvl => Err(format_err!("Invalid logging level: {}", lvl)),
+ lvl => Err(anyhow!("Invalid logging level: {}", lvl)),
}
}
@@ -175,10 +172,8 @@ fn aggregate_global_loglevel(matches: &ArgMatches, config: Option<&Value>) -> Re
if let Some(cfg) = config {
let cfg_loglevel = cfg
- .read_string("imag.logging.level")
- .map_err(Error::from)
- .context(EM::TomlQueryError)?
- .ok_or_else(|| err_msg("Global log level config missing"))
+ .read_string("imag.logging.level")?
+ .ok_or_else(|| anyhow!("Global log level config missing"))
.and_then(|s| match_log_level_str(&s))?;
if let Some(cli_loglevel) = get_arg_loglevel(matches)? {
@@ -208,8 +203,6 @@ fn translate_destination(raw: &str) -> Result<LogDestination> {
.map(Arc::new)
.map(LogDestination::File)
.map_err(Error::from)
- .context(EM::IO)
- .map_err(Error::from)
}
}
}
@@ -218,21 +211,18 @@ fn aggregate_global_destinations(config: Option<&Value>) -> Result<Vec<LogDestin
match config {
None => Ok(vec![LogDestination::default()]),
Some(cfg) => cfg
- .read("imag.logging.destinations")
- .map_err(Error::from)
- .context(EM::TomlQueryError)?
- .ok_or_else(|| err_msg("Global log destination config missing"))?
+ .read("imag.logging.destinations")?
+ .ok_or_else(|| anyhow!("Global log destination config missing"))?
.as_array()
.ok_or_else(|| {
let msg = "Type error at 'imag.logging.destinations', expected 'Array'";
- err_msg(msg)
+ anyhow!(msg)
})
.and_then(|raw| {
raw.iter()
.map(|val| {
val.as_str()
- .ok_or_else(|| "Type error at 'imag.logging.modules.<mod>.destinations', expected Array<String>")
- .map_err(err_msg)
+ .ok_or_else(|| anyhow!("Type error at 'imag.logging.modules.<mod>.destinations', expected Array<String>"))
.map_err(Error::from)
.and_then(|s| translate_destination(s))
})
@@ -242,29 +232,24 @@ fn aggregate_global_destinations(config: Option<&Value>) -> Result<Vec<LogDestin
}
mod log_lvl_aggregate {
- use failure::Fallible as Result;
- use failure::Error as E;
- use failure::ResultExt;
- use failure::err_msg;
+ use anyhow::Result;
+ use anyhow::Error as E;
+ use anyhow::Context;
use toml::Value;
use toml_query::read::TomlValueReadTypeExt;
use handlebars::Handlebars;
- use libimagerror::errors::ErrorMsg as EM;
-
macro_rules! aggregate_global_format_with {
($t:ident, $read_str:expr) => {
pub struct $t;
impl LogLevelAggregator for $t {
fn aggregate(config: Option<&Value>) -> Result<String> {
config.ok_or_else(|| {
- E::from(err_msg(concat!("Config missing: Logging format: ", stringify!($t))))
+ E::from(anyhow!(concat!("Config missing: Logging format: ", stringify!($t))))
})?
- .read_string($read_str)
- .map_err(E::from)
- .context(EM::TomlQueryError)?
+ .read_string($read_str)?
.ok_or_else(|| {
- E::from(err_msg(concat!("Config missing: Logging format: ", stringify!($t))))
+ E::from(anyhow!(concat!("Config missing: Logging format: ", stringify!($t))))
})
}
}
@@ -280,7 +265,7 @@ mod log_lvl_aggregate {
{
hb.register_template_string(lvlstr, T::aggregate(config)?)
.map_err(E::from)
- .context(err_msg("Handlebars template error"))
+ .context(anyhow!("Handlebars template error"))
.map_err(E::from)
}