logma/
lib.rs

1pub mod logma {
2    #[macro_export]
3    macro_rules! info {
4        ($fmt:expr) => {
5            println!("{} {}", "[INFO]", $fmt)
6        };
7
8        ($fmt:expr, $($args:tt)*) => {
9            println!("{} {}", "[INFO]", format_args!($fmt, $($args)*))
10        };
11    }
12
13    #[macro_export]
14    macro_rules! warn {
15        ($fmt:expr) => {
16            println!("{} {}",
17                colored::Colorize::yellow("[WARN]"),
18                colored::Colorize::yellow($fmt)
19            )
20        };
21
22        ($fmt:expr, $($args:tt)*) => {
23            println!("{} {}",
24                colored::Colorize::yellow("[WARN]"),
25                colored::Colorize::yellow(format_args!($fmt, $($args)*).to_string().as_str()),
26            )
27        };
28    }
29
30    #[macro_export]
31    macro_rules! fatal {
32        ($fmt:expr) => {
33            println!("{} {}",
34                colored::Colorize::red("[FATAL]"),
35                colored::Colorize::red($fmt)
36            )
37        };
38
39        ($fmt:expr, $($args:tt)*) => {
40            println!("{} {}",
41                colored::Colorize::red("[FATAL]"),
42                colored::Colorize::red(format_args!($fmt, $($args)*).to_string().as_str()),
43            )
44        };
45    }
46
47    #[macro_export]
48    macro_rules! debug {
49        ($fmt:expr) => {
50            if cfg!(debug_assertions) {
51                println!("{} {}",
52                    colored::Colorize::bright_black("[DEBUG]"),
53                    colored::Colorize::bright_black($fmt)
54                )
55            }
56        };
57
58        ($fmt:expr, $($args:tt)*) => {
59            if cfg!(debug_assertions) {
60                println!("{} {}",
61                    colored::Colorize::bright_black("[DEBUG]"),
62                    colored::Colorize::bright_black(format_args!($fmt, $($args)*).to_string().as_str())
63                )
64            }
65        };
66    }
67
68    #[macro_export]
69    macro_rules! custom {
70        ($text:expr, $fmt:expr) => {
71            println!("{} {}", $text, $fmt)
72        };
73
74        // not working yet
75        // ($text:expr, $fmt:expr, $($args:tt)*) => {
76        //     println!("{} {}", $text, format_args!($fmt, $($args)*))
77        // };
78    }
79}
80
81// todo: error variants
82
83// example use
84/*
85        use logma::*;
86
87        logma!(info, "this is a test");
88        logma!(warn, "this is a test");
89        logma!(fatal, "this is a test");
90        logma!(debug, "this is a test");
91        logma!(custom, "[LMAO]".truecolor(255, 0, 255), "this is a test".truecolor(255, 0, 255));
92
93        logma!(info, "{} hi :)", "this is a test");
94        logma!(warn, "{} hi :)", "this is a test");
95        logma!(fatal, "{} hi :)", "this is a test");
96        logma!(debug, "{} hi :)", "this is a test");
97        // not working yet
98        // logma!(custom, "[LMAO]".truecolor(255, 0, 255), "{} hi :)", "this is a test".truecolor(255, 0, 255));
99*/
100
101// its testing time //
102#[cfg(test)]
103mod tests {
104    use colored::Colorize;
105    use crate::*;
106
107    #[test]
108    fn test_normal() {
109        info!("this is a test");
110        warn!("this is a test");
111        fatal!("this is a test");
112        debug!("this is a test");
113        custom!("[CUSTOM]".truecolor(255, 0, 255), "this is a test".truecolor(255, 0, 255));
114    }
115
116    #[test]
117    fn test_format() {
118        info!("{} is a test", "this");
119        warn!("{} is a test", "this");
120        fatal!("{} is a test", "this");
121        debug!("{} is a test", "this");
122    }
123}