grafix_toolbox/kit/policies/func/
logging_def.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#[macro_export]
macro_rules! LOGGER {
	($f: path, $l: ident) => {
		let ___errors_logging_main_logger_sink = logging::Logger::initialize($f, logging::Level::$l);
	};
}

#[cfg(not(debug_assertions))]
#[macro_export]
macro_rules! ASSERT {
	(false, $($t: tt)+) => {{
		unreachable!();
	}};
	($e: expr, $($t: tt)+) => {{}};
}
#[cfg(debug_assertions)]
#[macro_export]
macro_rules! ASSERT {
	(false, $w: literal) => { ASSERT_IMPL!($w) };
	(false, $w: expr) => { ASSERT_IMPL!("{}", $w) };
	(false, $($t: tt)+) => { ASSERT_IMPL!($($t)+) };
	($e: expr, $w: literal) => { if $e {} else { ASSERT_IMPL!($w) } };
	($e: expr, $w: expr) => { if $e {} else { ASSERT_IMPL!("{}", $w) } };
	($e: expr, $($t: tt)+) => { if $e {} else { ASSERT_IMPL!($($t)+) } };
}
#[macro_export]
macro_rules! ASSERT_IMPL {
	($($t: tt)+) => {{
		use $crate::logging::*;
		Logger::log(format!("A| {} |{}:{}|{}\n", format!($($t)+), file!(), line!(), std::thread::current().name().unwrap_or("???")).red().to_string());
		std::panic::set_hook(std::boxed::Box::new(|_| {}));
		panic!();
	}};
}

#[macro_export]
macro_rules! ERROR {
	($e: literal) => { ERROR_IMPL!($e) };
	($e: expr) => { ERROR_IMPL!("{}", $e) };
	($($t: tt)+) => { ERROR_IMPL!($($t)+) };
}
#[macro_export]
macro_rules! ERROR_IMPL {
	($($t: tt)+) => {{
		use $crate::logging::*;
		let e = "E|".red().bold();
		let bt = process_backtrace(std::backtrace::Backtrace::force_capture());
		Logger::log(format!("{e} {bt}{e} {} |{}:{}|{}\n", format!($($t)+).red(), file!(), line!(), std::thread::current().name().unwrap_or("???")));
		std::panic::set_hook(std::boxed::Box::new(|_| {}));
		panic!();
	}};
}

#[cfg(not(debug_assertions))]
#[macro_export]
macro_rules! FAIL {
	($($t: tt)+) => { WARN!($($t)+) };
}
#[cfg(debug_assertions)]
#[macro_export]
macro_rules! FAIL {
	($($t: tt)+) => { ASSERT!(0 == 1, $($t)+) };
}

#[macro_export]
macro_rules! WARN {
	($e: literal) => { WARN_IMPL!($e) };
	($e: expr) => { WARN_IMPL!("{}", $e) };
	($($t: tt)+) => { WARN_IMPL!($($t)+) };
}
#[macro_export]
macro_rules! WARN_IMPL {
	($($t: tt)+) => {{
		use $crate::logging::*;
		if Level::WARNING as i32 <= Logger::level() {
			let w = "W| ".red().to_string();
			Logger::log([&w, &format!($($t)+), " |", file!(), ":", &line!().to_string(), "\n"].concat());
		}
	}};
}

#[macro_export]
macro_rules! INFO {
	($e: literal) => { INFO_IMPL!($e) };
	($e: expr) => { INFO_IMPL!("{}", $e) };
	($($t: tt)+) => { INFO_IMPL!($($t)+) };
}
#[macro_export]
macro_rules! INFO_IMPL {
	($($t: tt)+) => {{
		use $crate::logging::*;
		if Level::INFO as i32 <= Logger::level() {
			Logger::log(["I| ", &format!($($t)+), " |", file!(), ":", &line!().to_string(), "\n"].concat());
		}
	}};
}

#[cfg(not(debug_assertions))]
#[macro_export]
macro_rules! DEBUG {
	($($t: tt)+) => {{}};
}
#[cfg(debug_assertions)]
#[macro_export]
macro_rules! DEBUG {
	($e: literal) => { DEBUG_IMPL!($e) };
	($e: expr) => { DEBUG_IMPL!("{}", $e) };
	($($t: tt)+) => { DEBUG_IMPL!($($t)+) };
}
#[macro_export]
macro_rules! DEBUG_IMPL {
	($($t: tt)+) => {{
		use $crate::logging::*;
		if Level::DEBUG as i32 <= Logger::level() {
			Logger::log(["D| ", &format!($($t)+), "\n"].concat());
		}
	}};
}

#[macro_export]
macro_rules! PRINT {
	($e: literal) => { PRINT_IMPL!($e) };
	($e: expr) => { PRINT_IMPL!("{}", $e) };
	($($t: tt)+) => { PRINT_IMPL!($($t)+) };
}
#[macro_export]
macro_rules! PRINT_IMPL {
	($($t: tt)+) => {{
		use $crate::logging::*;
		if Level::PRINT as i32 <= Logger::level() {
			let mut msg = format!($($t)+);
			msg.push('\n');
			Logger::log( msg);
		}
	}};
}