grafix_toolbox/kit/policies/func/
logging_def.rs

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