Better debug messages and logging handling

This commit is contained in:
Lucien Cartier-Tilet 2020-07-11 17:51:38 +02:00
parent 78541f10ba
commit 9cc1a52e5a
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA
2 changed files with 45 additions and 22 deletions

View File

@ -40,24 +40,39 @@ pub mod utils;
/// lang_evolve_core::init();
/// ```
pub fn init() -> std::result::Result<(), log::SetLoggerError> {
match CombinedLogger::init(vec![
TermLogger::new(
LevelFilter::Warn,
Config::default(),
TerminalMode::Mixed,
)
.unwrap(),
WriteLogger::new(
LevelFilter::Debug,
Config::default(),
File::create("core.log").unwrap(),
),
WriteLogger::new(
LevelFilter::Info,
Config::default(),
File::create("core.log").unwrap(),
),
]) {
// #[cfg(debug_assertions)]
match CombinedLogger::init(if cfg!(debug_assertions) {
vec![
WriteLogger::new(
LevelFilter::Warn,
Config::default(),
File::create("core.log").unwrap(),
),
WriteLogger::new(
LevelFilter::Debug,
Config::default(),
File::create("core.log").unwrap(),
),
WriteLogger::new(
LevelFilter::Info,
Config::default(),
File::create("core.log").unwrap(),
),
]
} else {
vec![
WriteLogger::new(
LevelFilter::Warn,
Config::default(),
File::create("core.log").unwrap(),
),
WriteLogger::new(
LevelFilter::Info,
Config::default(),
File::create("core.log").unwrap(),
),
]
}) {
Err(why) => {
warn!("Could not initialize logger: {}", why.to_string());
Err(why)

View File

@ -347,16 +347,24 @@ impl Settings {
debug!("===============================================");
for rule in rules {
debug!(
"from: {}\tto: {}",
"from: \"{}\"\tto: \"{}\"",
rule.get_from().to_string(),
rule.get_to()
);
debug!("old: {}", s);
s = rule
let old = s.clone();
let new = rule
.get_from()
.replace_all(&s, rule.get_to().as_str())
.to_string();
debug!("new: {}", s);
if cfg!(debug_assertions) {
let diffs = diff_words(&old, &new);
if diffs.diff().len() > 1 {
debug!("diff:\n{}", diff_words(&old, &new));
} else {
debug!("diff: No changes");
}
}
s = new;
}
Ok(s)
}