Skip to main content

grafix_toolbox/kit/policies/func/
log.rs

1#[macro_export]
2macro_rules! LOGGER {
3	($f: expr, $l: ident) => {
4		let ___errors_logger_main_logger_sink = logger::Logger::init($f, logger::Level::$l);
5	};
6}
7
8#[cfg(not(debug_assertions))]
9#[macro_export]
10macro_rules! ASSERT {
11	($e: expr, $($t: tt)+) => {{}};
12}
13#[cfg(debug_assertions)]
14#[macro_export]
15macro_rules! ASSERT {
16	($e: expr, $w: literal) => { if $e {} else { ERROR_IMPL!($w) } };
17	($e: expr, $w: expr) => { if $e {} else { ERROR_IMPL!("{}", $w) } };
18	($e: expr, $($t: tt)+) => { if $e {} else { ERROR_IMPL!($($t)+) } };
19}
20
21#[macro_export]
22macro_rules! ERROR {
23	($e: literal) => { ERROR_IMPL!($e) };
24	($e: expr) => { ERROR_IMPL!("{}", $e) };
25	($($t: tt)+) => { ERROR_IMPL!($($t)+) };
26}
27#[macro_export]
28macro_rules! ERROR_IMPL {
29	($($t: tt)+) => {{
30		use $crate::logger::*;
31		let (bt, e) = (process_backtrace(std::backtrace::Backtrace::force_capture()), "E|".red().bold());
32		Logger::log(format!("{e} {bt}{e} {} |{}:{}|{}\n", format!($($t)+).red(), file!(), line!(), std::thread::current().name().unwrap_or("???")));
33		std::panic::set_hook(std::boxed::Box::new(|_| {}));
34		panic!()
35	}};
36}
37
38#[cfg(not(debug_assertions))]
39#[macro_export]
40macro_rules! FAIL {
41	($b: block, $($t: tt)+) => {{ WARN!($($t)+); $b }};
42	($($t: tt)+) => { WARN!($($t)+) };
43}
44#[cfg(debug_assertions)]
45#[macro_export]
46macro_rules! FAIL {
47	($b: block, $($t: tt)+) => { ERROR!($($t)+) };
48	($($t: tt)+) => { ERROR!($($t)+) };
49}
50
51#[macro_export]
52macro_rules! WARN {
53	($e: literal) => { WARN_IMPL!($e) };
54	($e: expr) => { WARN_IMPL!("{}", $e) };
55	($($t: tt)+) => { WARN_IMPL!($($t)+) };
56}
57#[macro_export]
58macro_rules! WARN_IMPL {
59	($($t: tt)+) => {{
60		use $crate::logger::*;
61		if Level::WARNING as i32 <= Logger::level() {
62			let w = "W| ".red().to_string();
63			Logger::log([&w, &format!($($t)+), " |", file!(), ":", &line!().to_string(), "\n"].concat());
64		}
65	}};
66}
67
68#[macro_export]
69macro_rules! INFO {
70	($e: literal) => { INFO_IMPL!($e) };
71	($e: expr) => { INFO_IMPL!("{}", $e) };
72	($($t: tt)+) => { INFO_IMPL!($($t)+) };
73}
74#[macro_export]
75macro_rules! INFO_IMPL {
76	($($t: tt)+) => {{
77		use $crate::logger::*;
78		if Level::INFO as i32 <= Logger::level() {
79			Logger::log(["I| ", &format!($($t)+), " |", file!(), ":", &line!().to_string(), "\n"].concat());
80		}
81	}};
82}
83
84#[cfg(not(debug_assertions))]
85#[macro_export]
86macro_rules! DEBUG {
87	($($t: tt)+) => {{}};
88}
89#[cfg(debug_assertions)]
90#[macro_export]
91macro_rules! DEBUG {
92	($e: literal) => { DEBUG_IMPL!($e) };
93	($e: expr) => { DEBUG_IMPL!("{}", $e) };
94	($($t: tt)+) => { DEBUG_IMPL!($($t)+) };
95}
96#[macro_export]
97macro_rules! DEBUG_IMPL {
98	($($t: tt)+) => {{
99		use $crate::logger::*;
100		if Level::DEBUG as i32 <= Logger::level() {
101			Logger::log(["D| ", &format!($($t)+), "\n"].concat());
102		}
103	}};
104}
105
106#[macro_export]
107macro_rules! PRINT {
108	($e: literal) => { PRINT_IMPL!($e) };
109	($e: expr) => { PRINT_IMPL!("{}", $e) };
110	($($t: tt)+) => { PRINT_IMPL!($($t)+) };
111}
112#[macro_export]
113macro_rules! PRINT_IMPL {
114	($($t: tt)+) => {{
115		use $crate::logger::*;
116		if Level::PRINT as i32 <= Logger::level() {
117			let mut msg = format!($($t)+);
118			msg.push('\n');
119			Logger::log(msg);
120		}
121	}};
122}