1pub mod logger;
36pub mod config;
37pub mod formatter;
38pub mod rotation;
39pub mod colors;
40
41pub use logger::Logger;
42pub use config::{Config, LogLevel, OutputTarget};
43
44use std::sync::Once;
45
46static INIT: Once = Once::new();
47
48pub fn init() {
50 INIT.call_once(|| {
51 let config = Config::from_env();
52 Logger::init(config).expect("Failed to initialize logger");
53 });
54}
55
56pub fn init_with_config(config: Config) {
58 INIT.call_once(|| {
59 Logger::init(config).expect("Failed to initialize logger");
60 });
61}
62
63#[macro_export]
65macro_rules! trace {
66 ($($arg:tt)*) => {
67 $crate::logger::log($crate::LogLevel::Trace, format_args!($($arg)*))
68 };
69}
70
71#[macro_export]
73macro_rules! debug {
74 ($($arg:tt)*) => {
75 $crate::logger::log($crate::LogLevel::Debug, format_args!($($arg)*))
76 };
77}
78
79#[macro_export]
81macro_rules! info {
82 ($($arg:tt)*) => {
83 $crate::logger::log($crate::LogLevel::Info, format_args!($($arg)*))
84 };
85}
86
87#[macro_export]
89macro_rules! warn {
90 ($($arg:tt)*) => {
91 $crate::logger::log($crate::LogLevel::Warn, format_args!($($arg)*))
92 };
93}
94
95#[macro_export]
97macro_rules! error {
98 ($($arg:tt)*) => {
99 $crate::logger::log($crate::LogLevel::Error, format_args!($($arg)*))
100 };
101}
102
103#[cfg(test)]
104mod tests {
105 use super::*;
106
107 #[test]
108 fn test_macros() {
109 init();
110 trace!("This is a trace message");
111 debug!("This is a debug message");
112 info!("This is an info message");
113 warn!("This is a warning message");
114 error!("This is an error message");
115 }
116}