Style: Automatische Formatierung & Clippy-Fixes
TruffleHog Secret Scan / TruffleHog (push) Successful in 16s
Security Scans / Trivy & OSV-Scanner (push) Successful in 26s
Code Quality (Auto-Format & Clippy-Fix) / Formatierung & Clippy automatisch beheben (push) Successful in 28s

This commit is contained in:
2026-09-12 22:36:04 +00:00
parent 01f6948c2b
commit 3abd8d9c24
2 changed files with 31 additions and 15 deletions
+9 -9
View File
@@ -23,13 +23,13 @@
use std::env;
use std::fmt::{Display, Formatter};
use std::fs::{create_dir_all, File, OpenOptions};
use std::fs::{File, OpenOptions, create_dir_all};
use std::io::Write;
use std::path::PathBuf;
use std::str::FromStr;
use std::sync::atomic::{AtomicU8, Ordering};
use std::sync::{Mutex, OnceLock, RwLock};
use time::{macros::format_description, OffsetDateTime};
use time::{OffsetDateTime, macros::format_description};
/// Schweregrade für Logeinträge in aufsteigender Detailtiefe.
///
@@ -139,11 +139,10 @@ pub fn get_log_level() -> LogLevel {
};
}
if let Ok(val) = env::var("LOG_LEVEL").or_else(|_| env::var("RUST_LOG")) {
if let Ok(lvl) = LogLevel::try_from(val.as_str()) {
if let Ok(val) = env::var("LOG_LEVEL").or_else(|_| env::var("RUST_LOG"))
&& let Ok(lvl) = LogLevel::try_from(val.as_str()) {
return lvl;
}
}
LogLevel::Info
}
@@ -183,7 +182,9 @@ pub fn format_message(tag: &str, message: &str, log_level: &LogLevel) -> String
let message = format!(
"[{}][{}]{}: {}",
now_local.format(fmt).unwrap_or_else(|_| "00.00.0000 00:00:00.000".to_string()),
now_local
.format(fmt)
.unwrap_or_else(|_| "00.00.0000 00:00:00.000".to_string()),
log_level,
prefix,
message
@@ -228,13 +229,12 @@ pub fn log(tag: &str, message: &str, log_level: LogLevel) {
}
let file_lock = get_or_init_log_file();
if let Ok(mut guard) = file_lock.lock() {
if let Some(f) = guard.as_mut() {
if let Ok(mut guard) = file_lock.lock()
&& let Some(f) = guard.as_mut() {
let _ = writeln!(f, "{}", formatted);
let _ = f.flush();
}
}
}
}
/// Schreibt einen Log-Eintrag mit Schweregrad `Error`.
+22 -6
View File
@@ -1,6 +1,6 @@
use logger_ctdra::{
debug, error, format_message, get_log_level, info, init, log, set_log_dir, set_log_level,
warn, LogLevel,
LogLevel, debug, error, format_message, get_log_level, info, init, log, set_log_dir,
set_log_level, warn,
};
use std::env;
use std::str::FromStr;
@@ -152,13 +152,29 @@ fn test_convenience_functions() {
fn test_log_filtering_behavior() {
set_log_level(LogLevel::Error);
// Debug and Info should be filtered out, Error should pass
log("filter_test", "This debug log should be ignored", LogLevel::Debug);
log("filter_test", "This info log should be ignored", LogLevel::Info);
log("filter_test", "This warn log should be ignored", LogLevel::Warn);
log(
"filter_test",
"This debug log should be ignored",
LogLevel::Debug,
);
log(
"filter_test",
"This info log should be ignored",
LogLevel::Info,
);
log(
"filter_test",
"This warn log should be ignored",
LogLevel::Warn,
);
log("filter_test", "This error log should pass", LogLevel::Error);
set_log_level(LogLevel::Debug);
log("filter_test", "All logs should pass in Debug level", LogLevel::Debug);
log(
"filter_test",
"All logs should pass in Debug level",
LogLevel::Debug,
);
}
#[test]