Better debug messages and logging handling
This commit is contained in:
parent
78541f10ba
commit
9cc1a52e5a
51
src/lib.rs
51
src/lib.rs
@ -40,24 +40,39 @@ pub mod utils;
|
|||||||
/// lang_evolve_core::init();
|
/// lang_evolve_core::init();
|
||||||
/// ```
|
/// ```
|
||||||
pub fn init() -> std::result::Result<(), log::SetLoggerError> {
|
pub fn init() -> std::result::Result<(), log::SetLoggerError> {
|
||||||
match CombinedLogger::init(vec![
|
// #[cfg(debug_assertions)]
|
||||||
TermLogger::new(
|
match CombinedLogger::init(if cfg!(debug_assertions) {
|
||||||
LevelFilter::Warn,
|
vec![
|
||||||
Config::default(),
|
WriteLogger::new(
|
||||||
TerminalMode::Mixed,
|
LevelFilter::Warn,
|
||||||
)
|
Config::default(),
|
||||||
.unwrap(),
|
File::create("core.log").unwrap(),
|
||||||
WriteLogger::new(
|
),
|
||||||
LevelFilter::Debug,
|
WriteLogger::new(
|
||||||
Config::default(),
|
LevelFilter::Debug,
|
||||||
File::create("core.log").unwrap(),
|
Config::default(),
|
||||||
),
|
File::create("core.log").unwrap(),
|
||||||
WriteLogger::new(
|
),
|
||||||
LevelFilter::Info,
|
WriteLogger::new(
|
||||||
Config::default(),
|
LevelFilter::Info,
|
||||||
File::create("core.log").unwrap(),
|
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) => {
|
Err(why) => {
|
||||||
warn!("Could not initialize logger: {}", why.to_string());
|
warn!("Could not initialize logger: {}", why.to_string());
|
||||||
Err(why)
|
Err(why)
|
||||||
|
@ -347,16 +347,24 @@ impl Settings {
|
|||||||
debug!("===============================================");
|
debug!("===============================================");
|
||||||
for rule in rules {
|
for rule in rules {
|
||||||
debug!(
|
debug!(
|
||||||
"from: {}\tto: {}",
|
"from: \"{}\"\tto: \"{}\"",
|
||||||
rule.get_from().to_string(),
|
rule.get_from().to_string(),
|
||||||
rule.get_to()
|
rule.get_to()
|
||||||
);
|
);
|
||||||
debug!("old: {}", s);
|
let old = s.clone();
|
||||||
s = rule
|
let new = rule
|
||||||
.get_from()
|
.get_from()
|
||||||
.replace_all(&s, rule.get_to().as_str())
|
.replace_all(&s, rule.get_to().as_str())
|
||||||
.to_string();
|
.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)
|
Ok(s)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user