use super::basic::LogInfo;
use crate::core::config::LogLevel;
pub fn format_detailed(info: &LogInfo) -> String {
match (info.file, info.line) {
(Some(file), Some(line)) => {
format!(
"[{}] [{}:{}] {}: {}",
info.timestamp,
file,
line,
info.level.as_str(),
info.message
)
}
(Some(file), None) => {
format!(
"[{}] [{}] {}: {}",
info.timestamp,
file,
info.level.as_str(),
info.message
)
}
(None, _) => {
format!(
"[{}] {}: {}",
info.timestamp,
info.level.as_str(),
info.message
)
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_detailed_formatting_with_full_location() {
let info = LogInfo::new(
"Test message",
LogLevel::Info,
"2025-09-06 15:30:45"
).with_location("main.rs", 42);
let result = format_detailed(&info);
assert_eq!(result, "[2025-09-06 15:30:45] [main.rs:42] INFO: Test message");
}
#[test]
fn test_detailed_formatting_with_file_only() {
let mut info = LogInfo::new(
"Test message",
LogLevel::Warning,
"2025-09-06 15:30:45"
);
info.file = Some("utils.rs");
let result = format_detailed(&info);
assert_eq!(result, "[2025-09-06 15:30:45] [utils.rs] WARNING: Test message");
}
#[test]
fn test_detailed_formatting_fallback_to_basic() {
let info = LogInfo::new(
"Test message",
LogLevel::Error,
"2025-09-06 15:30:45"
);
let result = format_detailed(&info);
assert_eq!(result, "[2025-09-06 15:30:45] ERROR: Test message");
}
#[test]
fn test_different_log_levels() {
let info = LogInfo::new(
"Debug info",
LogLevel::Debug,
"2025-09-06 15:30:45"
).with_location("debug.rs", 123);
let result = format_detailed(&info);
assert_eq!(result, "[2025-09-06 15:30:45] [debug.rs:123] DEBUG: Debug info");
}
}