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 }
79}
80
81#[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}