Logging #26

Open
leon wants to merge 33 commits from Logging into main
2 changed files with 26 additions and 2 deletions
Showing only changes of commit a36a8a8b76 - Show all commits

View File

@ -103,6 +103,9 @@ macro_rules! log {
log_message($msg, &*conf, file!(), line!(), column!()); log_message($msg, &*conf, file!(), line!(), column!());
drop(conf); drop(conf);
}; };
($msg:expr, $config:expr) => {
log_message($msg, $config, file!(), line!(), column!());
};
} }
/** /**

View File

@ -35,6 +35,27 @@ static LOG_DIR: Lazy<String> = Lazy::new(|| {
} }
}); });
/// Tests if the macro logs properly with a given config.
#[test]
pub fn log_macro_given_config()
{
let log_path = &format!("{}/{}", *LOG_DIR, Uuid::new_v4());
println!("Log Path: {log_path}");
let message = LogMessageType::GenericWarn(String::from("Test Log")).log_message();
let mut config = config::DEFAULTS;
config.set_log_path(PathBuf::from(log_path));
create_dir_all(PathBuf::from(LOG_DIR.as_str()))
.unwrap_or_else(|_| panic!("Could not create directory: {}", *LOG_DIR));
log!(&message, &config);
let log_file = read_to_string(PathBuf::from(log_path))
.unwrap_or_else(|_| panic!("Could not read file: {log_path}"));
assert_eq!(message.to_string() + "\n", log_file);
}
/// Tests if [`log_message`] to file correctly. /// Tests if [`log_message`] to file correctly.
#[test] #[test]
pub fn log_msg_file() { pub fn log_msg_file() {
@ -153,7 +174,7 @@ pub fn verbosity_filter() {
*/ */
#[test] #[test]
pub fn concurrency_tests() { pub fn concurrency_tests() {
log_macro_file(); log_macro_shared_config();
log_concurrently_any_order(); log_concurrently_any_order();
log_concurrently_correct_order(); log_concurrently_correct_order();
} }
@ -162,7 +183,7 @@ pub fn concurrency_tests() {
* Tests if log macro logs to file correctly. * Tests if log macro logs to file correctly.
* [`config::CONFIG`] * [`config::CONFIG`]
*/ */
fn log_macro_file() { fn log_macro_shared_config() {
let log_path = &format!("{}/{}", *LOG_DIR, Uuid::new_v4()); let log_path = &format!("{}/{}", *LOG_DIR, Uuid::new_v4());
println!("Log Path: {log_path}"); println!("Log Path: {log_path}");
let message = LogMessageType::GenericWarn(String::from("Test Log")).log_message(); let message = LogMessageType::GenericWarn(String::from("Test Log")).log_message();