From 67ea522d3f2f8be2261c68ac1efb67249956e134 Mon Sep 17 00:00:00 2001 From: SARDONYX-sard <68905624+SARDONYX-sard@users.noreply.github.com> Date: Thu, 9 Nov 2023 15:22:15 +0900 Subject: [PATCH] refactor(core-logger): organize log msg --- Cargo.lock | 1 - dar2oar_core/Cargo.toml | 3 +-- dar2oar_core/src/condition_parser/conditions.rs | 5 ++--- dar2oar_core/src/condition_parser/mod.rs | 10 ++++++++-- dar2oar_core/src/fs/path_changer.rs | 2 +- dar2oar_core/src/fs/sequential.rs | 3 ++- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 421f181..3c0a53c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -810,7 +810,6 @@ dependencies = [ "async-walkdir", "criterion", "jwalk", - "log", "nom", "once_cell", "pretty_assertions", diff --git a/dar2oar_core/Cargo.toml b/dar2oar_core/Cargo.toml index 6181e4e..9b7426a 100644 --- a/dar2oar_core/Cargo.toml +++ b/dar2oar_core/Cargo.toml @@ -14,7 +14,6 @@ rust-version = "1.60" anyhow = { version = "1.0.75", features = ["backtrace"] } async-walkdir = "0.2.0" # To traverse dir recursivly(Single thiread) jwalk = "0.8.1" # To parallel traverse dir recursivly -log = "0.4.20" # Logger nom = { version = "7.1.3", features = ["alloc"] } # Syntax serde = { version = "1.0", features = ["derive"] } # Implement (De)Serializer serde_json = "1.0" # Json converter @@ -26,7 +25,7 @@ tokio = { version = "1.33.0", features = [ "rt", ] } # Async Executor tokio-stream = "0.1.14" # Async next() method -tracing = "0.1.40" +tracing = "0.1.40" # Logger [dev-dependencies] criterion = { version = "0.5.1", features = [ diff --git a/dar2oar_core/src/condition_parser/conditions.rs b/dar2oar_core/src/condition_parser/conditions.rs index 89ba22d..77f1aac 100644 --- a/dar2oar_core/src/condition_parser/conditions.rs +++ b/dar2oar_core/src/condition_parser/conditions.rs @@ -119,11 +119,10 @@ fn parse_condition(condition: Expression<'_>) -> Result { - log::debug!("Condition({fn_name}) has no explicit mapping."); - + tracing::debug!("Condition({fn_name}) has no explicit mapping."); ConditionSet::Condition(Condition { + condition: fn_name.into(), negated, - condition: fn_name.to_string(), ..Default::default() }) } diff --git a/dar2oar_core/src/condition_parser/mod.rs b/dar2oar_core/src/condition_parser/mod.rs index 566f373..04c6e96 100644 --- a/dar2oar_core/src/condition_parser/mod.rs +++ b/dar2oar_core/src/condition_parser/mod.rs @@ -14,7 +14,10 @@ use anyhow::bail; pub fn parse_dar2oar(input: &str) -> anyhow::Result> { let (_, dar_syn) = match parse_condition(input) { - Ok(syn) => syn, + Ok(syn) => { + tracing::debug!("Input => Parsed DAR:\n{:?}", syn); + syn + } Err(err) => { let err = match err { nom::Err::Incomplete(_) => bail!("Error Incomplete"), @@ -24,5 +27,8 @@ pub fn parse_dar2oar(input: &str) -> anyhow::Result> { bail!(convert_error(input, err)); } }; - Ok(parse_conditions(dar_syn)?.try_into()?) + + let oar = parse_conditions(dar_syn)?; + tracing::debug!("Parsed DAR => Serializable OAR:\n{:?}", oar); + Ok(oar.try_into()?) } diff --git a/dar2oar_core/src/fs/path_changer.rs b/dar2oar_core/src/fs/path_changer.rs index 6fe9994..667456a 100644 --- a/dar2oar_core/src/fs/path_changer.rs +++ b/dar2oar_core/src/fs/path_changer.rs @@ -83,7 +83,7 @@ pub fn parse_dar_path(path: impl AsRef, dar_dirname: Option<&str>) -> DarP .or(Some({ path.parse::() .is_err() - .then(|| log::debug!("Expected a priority dir name with numbers, but got \"{path}\" (perhaps a dir name as a memo).")); + .then(|| tracing::debug!("Expected a priority dir name with numbers, but got \"{path}\" (perhaps a dir name as a memo).")); path.to_owned() })) }) diff --git a/dar2oar_core/src/fs/sequential.rs b/dar2oar_core/src/fs/sequential.rs index a91dd60..4f51d47 100644 --- a/dar2oar_core/src/fs/sequential.rs +++ b/dar2oar_core/src/fs/sequential.rs @@ -40,12 +40,13 @@ where let mut dar_1st_namespace = None; // To need rename to hidden(For _1stperson) let walk_len = WalkDir::new(&dar_dir).collect::>().await.len(); // Lower performance cost when sender is None. - log::debug!("Dir & File Counts: {}", walk_len); + tracing::trace!("Send all dirs & files counts: {}", walk_len); tokio::spawn(async_fn(walk_len)); let mut entries = WalkDir::new(dar_dir); let mut idx = 0usize; while let Some(entry) = entries.next().await { + tracing::trace!("Send Dir or file index: {}", idx); tokio::spawn(async_fn(idx)); idx += 1;