From 1c4fbd197e7f0fa72e5f8eb4e195fdaaa5933ac6 Mon Sep 17 00:00:00 2001 From: Manuel Hatzl Date: Sun, 23 Jul 2023 00:22:02 +0200 Subject: [PATCH 1/4] feat: use newest logid with filter --- Cargo.toml | 2 +- cli/src/compiler.rs | 6 +++--- cli/src/main.rs | 10 +++++----- commons/src/config/mod.rs | 4 ++-- commons/src/config/output.rs | 2 +- commons/src/config/preamble.rs | 18 +++++++++--------- parser/src/security/hashing.rs | 2 +- render/src/log_id.rs | 2 +- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a6d1267b..63871cfd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ readme = "README.md" license = "MIT" [workspace.dependencies] -logid = { version = "0.9", features = ["diagnostics"] } +logid = { version = "0.11", features = ["diagnostics"] } thiserror = "1.0" once_cell = "1.13.0" clap = { version = "4.2.7", features = ["derive", "cargo", "env"] } diff --git a/cli/src/compiler.rs b/cli/src/compiler.rs index dd8bcc5d..0d4de32c 100644 --- a/cli/src/compiler.rs +++ b/cli/src/compiler.rs @@ -24,7 +24,7 @@ pub fn compile(config: Config) -> Result<(), GeneralError> { let source = fs::read_to_string(&config.input).map_err(|error| { pipe!( GeneralError::FileRead, - &format!("Could not read file: '{:?}'", &config.input), + format!("Could not read file: '{:?}'", &config.input), add: AddonKind::Info(format!("Cause: {}", error)) ) })?; @@ -66,13 +66,13 @@ fn write_file( log!( GeneralInfo::WritingToFile, - &format!("Writing to file: {:?}", full_out_path), + format!("Writing to file: {:?}", full_out_path), ); std::fs::write(&full_out_path, content).map_err(|error| { pipe!( GeneralError::FileWrite, - &format!("Could not write to file: {:?}", full_out_path), + format!("Could not write to file: {:?}", full_out_path), add: AddonKind::Info(format!("Cause: {}", error)) ) }) diff --git a/cli/src/main.rs b/cli/src/main.rs index 08d90583..ea80a014 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,5 +1,5 @@ use clap::Parser; -use logid::{event_handler::LogEventHandlerBuilder, log, logging::event_entry::AddonKind}; +use logid::{event_handler::builder::LogEventHandlerBuilder, log, logging::event_entry::AddonKind}; use unimarkup_commons::config::{Config, ConfigFns}; use crate::log_id::{GeneralError, GeneralInfo}; @@ -8,8 +8,10 @@ mod compiler; mod log_id; fn main() { - let log_handler = LogEventHandlerBuilder::new() - .write_to_console() + let _ = logid::set_filter!("info(infos)"); + + let _handler = LogEventHandlerBuilder::new() + .to_stderr() .all_log_events() .build(); @@ -38,6 +40,4 @@ fn main() { ); } } - - log_handler.shutdown(); } diff --git a/commons/src/config/mod.rs b/commons/src/config/mod.rs index ca680fdb..803ffdaf 100644 --- a/commons/src/config/mod.rs +++ b/commons/src/config/mod.rs @@ -73,7 +73,7 @@ impl ConfigFns for Config { if !self.input.exists() { return err!( ConfigErr::InvalidFile, - &format!("Input file not found: {:?}", self.input) + format!("Input file not found: {:?}", self.input) ); } Ok(()) @@ -89,7 +89,7 @@ impl Config { .map_err(|_| { pipe!( ConfigErr::InvalidFile, - &format!( + format!( "Failed to read locales file: {:?}", locales_file.as_ref().map(|p| p.to_string_lossy()) ) diff --git a/commons/src/config/output.rs b/commons/src/config/output.rs index a82d82cc..2d696a61 100644 --- a/commons/src/config/output.rs +++ b/commons/src/config/output.rs @@ -41,7 +41,7 @@ impl ConfigFns for Output { if filepath.exists() { return err!( ConfigErr::InvalidConfig, - &format!( + format!( "Output file '{:?}' already exists, but `overwrite` was not set.", filepath ) diff --git a/commons/src/config/preamble.rs b/commons/src/config/preamble.rs index 5161ade2..51ad8a37 100644 --- a/commons/src/config/preamble.rs +++ b/commons/src/config/preamble.rs @@ -104,7 +104,7 @@ impl ConfigFns for I18n { .map_err(|_| { pipe!( ConfigErr::InvalidFile, - &format!( + format!( "Failed to read locales file: {}", self.locales_file.as_ref().unwrap().to_string_lossy() ) @@ -138,7 +138,7 @@ impl ConfigFns for I18n { provider.load_buffer(key, req).map_err(|err| { pipe!( ConfigErr::BadLocaleUsed, - &format!( + format!( "Could not find locale '{}' in data file. Cause: {}", locale, err ) @@ -183,7 +183,7 @@ impl I18n { Err(err) => { logid::log!( ConfigErr::InvalidFile, - &format!( + format!( "Locales file not found: {}. Cause: {}. Using default locales file.", file_path.to_string_lossy(), err @@ -208,7 +208,7 @@ impl I18n { let f = File::create(&file_path).map_err(|_| { pipe!( ConfigErr::FileCreate, - &format!( + format!( "Failed to create locales file: {}", file_path.as_ref().to_string_lossy() ) @@ -225,7 +225,7 @@ impl I18n { .map_err(|err| { pipe!( ConfigErr::LocaleDownload, - &format!( + format!( "Failed to download locales file: {}. Cause: {}", file_path.as_ref().to_string_lossy(), err, @@ -281,7 +281,7 @@ impl ConfigFns for Citedata { if !file.exists() { return err!( ConfigErr::InvalidFile, - &format!("Citation Style Language file not found: {:?}", file) + format!("Citation Style Language file not found: {:?}", file) ); } } @@ -290,7 +290,7 @@ impl ConfigFns for Citedata { if !reference.exists() { return err!( ConfigErr::InvalidFile, - &format!("Bibliography references file not found: {:?}", reference) + format!("Bibliography references file not found: {:?}", reference) ); } } @@ -327,7 +327,7 @@ impl ConfigFns for Metadata { if !font.exists() { return err!( ConfigErr::InvalidFile, - &format!("Font file not found: {:?}", font) + format!("Font file not found: {:?}", font) ); } } @@ -363,7 +363,7 @@ impl ConfigFns for HtmlSpecificParameter { if !fav.exists() { return err!( ConfigErr::InvalidFile, - &format!("Favicon file not found: {:?}", fav) + format!("Favicon file not found: {:?}", fav) ); } } diff --git a/parser/src/security/hashing.rs b/parser/src/security/hashing.rs index 04b39c6d..0357c512 100644 --- a/parser/src/security/hashing.rs +++ b/parser/src/security/hashing.rs @@ -13,7 +13,7 @@ pub fn get_filehash(file: &Path) -> Result, HashingError> { let source = fs::read_to_string(file).map_err(|err| { pipe!( HashingError::FailedReadingFile, - &format!("Could not read file: '{:?}'", file), + format!("Could not read file: '{:?}'", file), add: AddonKind::Info(format!("Cause: {}", err)) ) })?; diff --git a/render/src/log_id.rs b/render/src/log_id.rs index 8a203a65..99edf3ee 100644 --- a/render/src/log_id.rs +++ b/render/src/log_id.rs @@ -1,4 +1,4 @@ -use logid::{evident::event::intermediary::FinalizedEvent, log_id::LogId, ErrLogId}; +use logid::{evident::event::finalized::FinalizedEvent, log_id::LogId, ErrLogId}; use thiserror::Error; #[derive(Debug, Clone, ErrLogId, Error)] From f11ba842eb492b90199dd65916b983fa31bb3979 Mon Sep 17 00:00:00 2001 From: Manuel Hatzl Date: Sun, 23 Jul 2023 00:30:23 +0200 Subject: [PATCH 2/4] fix: remove string references for log msgs --- cli/src/main.rs | 2 +- commons/src/config/preamble.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index d71bdba9..57b61922 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -21,7 +21,7 @@ fn main() { if let Err(err) = cfg.validate() { logid::log!( GeneralError::Compile, - &format!("Configuration is invalid: {err}") + format!("Configuration is invalid: {err}") ); break 'outer; } diff --git a/commons/src/config/preamble.rs b/commons/src/config/preamble.rs index f56af269..b9cd91fe 100644 --- a/commons/src/config/preamble.rs +++ b/commons/src/config/preamble.rs @@ -94,7 +94,7 @@ impl ConfigFns for I18n { { return err!( ConfigErr::BadLocaleUsed, - &format!( + format!( "{} locale(s) not supported by default. Only the following locales are allowed: {}.", locales .iter() From fe3ed0a9829099b32277392ed0f3bdb000de536d Mon Sep 17 00:00:00 2001 From: Manuel Hatzl Date: Sun, 23 Jul 2023 01:00:36 +0200 Subject: [PATCH 3/4] fix: set stderr as log output for cli test --- cli/tests/logging/cli_logs.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/cli/tests/logging/cli_logs.rs b/cli/tests/logging/cli_logs.rs index 69ef1985..7406ba9e 100644 --- a/cli/tests/logging/cli_logs.rs +++ b/cli/tests/logging/cli_logs.rs @@ -13,20 +13,23 @@ fn test__main_log_trace__attributes_file() { path.push(format!("tests/test_files/{}", TEST_FILE)); let cli_proc = Command::new("cargo") - .stdout(Stdio::piped()) - .args(["run", "--", "--formats=html", &path.to_string_lossy()]) + .stderr(Stdio::piped()) + .args([ + "run", + "--", + "--formats=html", + "--lang=en", + &path.to_string_lossy(), + ]) .spawn() .expect("Failed to spawn 'cargo run'"); let output = cli_proc .wait_with_output() .expect("Failed to execute 'cargo run'"); - let logs = String::from_utf8_lossy(&output.stdout); + let logs = String::from_utf8_lossy(&output.stderr); - assert!(logs.contains("INFO: Writing to file: ")); + assert!(logs.contains("Writing to file: ")); assert!(logs.contains(&TEST_FILE.replace(".um", ".html"))); - // assert!(logs.contains("64(origin): file=")); - assert!(logs.contains("INFO: Unimarkup finished compiling.")); - // assert!(logs.contains(TEST_FILE)); - // assert!(logs.contains("65(origin): file=")); + assert!(logs.contains("Unimarkup finished compiling.")); } From 2a3b8075067cd3a0864bd347fc665cc697c27b4c Mon Sep 17 00:00:00 2001 From: Manuel Hatzl Date: Sat, 19 Aug 2023 15:18:38 +0200 Subject: [PATCH 4/4] feat: change to logid filter builder --- Cargo.toml | 2 +- cli/src/main.rs | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 63871cfd..66960b0c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ readme = "README.md" license = "MIT" [workspace.dependencies] -logid = { version = "0.11", features = ["diagnostics"] } +logid = { version = "0.12.1", features = ["diagnostics"] } thiserror = "1.0" once_cell = "1.13.0" clap = { version = "4.2.7", features = ["derive", "cargo", "env"] } diff --git a/cli/src/main.rs b/cli/src/main.rs index 57b61922..26698df1 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,5 +1,13 @@ use clap::Parser; -use logid::{event_handler::builder::LogEventHandlerBuilder, log, logging::event_entry::AddonKind}; +use logid::{ + event_handler::builder::LogEventHandlerBuilder, + log, + log_id::LogLevel, + logging::{ + event_entry::AddonKind, + filter::{AddonFilter, FilterConfigBuilder}, + }, +}; use unimarkup_commons::config::{Config, ConfigFns}; use crate::log_id::{GeneralError, GeneralInfo}; @@ -8,7 +16,11 @@ mod compiler; mod log_id; fn main() { - let _ = logid::set_filter!("info(infos)"); + let _ = logid::logging::filter::set_filter( + FilterConfigBuilder::new(LogLevel::Info) + .allowed_addons(AddonFilter::Infos) + .build(), + ); let _handler = LogEventHandlerBuilder::new() .to_stderr()