42 #include <string_view>
46 #define FILE_NAME_TAIL_LEN 50
101 static inline std::string_view view_tail(
const std::string& str, std::size_t len) {
102 return std::string_view{ str.data() + std::max<std::size_t>(0, str.length() - len) };
107 static inline auto lock_out() {
109 return std::lock_guard<std::mutex>{
logger_mtx };
118 [[maybe_unused]] auto static_logger_lck{ lock_out() }; \
119 std::cout << x << std::endl; \
124 # define _dont_write_log_err \
127 # define _write_log_err(level, x) \
129 [[maybe_unused]] auto static_logger_lck{ lock_out() }; \
130 std::cerr << level << x << TermColor::grey << "\n\t" << __func__ << "() in " \
131 << view_tail(__FILE__, FILE_NAME_TAIL_LEN) << " :" << __LINE__ << "" << TermColor::def \
135 # define _write_log_out(level, x) \
137 [[maybe_unused]] auto static_logger_lck{ lock_out() }; \
138 std::cout << level << x << TermColor::grey << "\n\t" << __func__ << "() in " \
139 << view_tail(__FILE__, FILE_NAME_TAIL_LEN) << " :" << __LINE__ << "" << TermColor::def \
144 # define SHLOG_E(x) _write_log_err(TermColor::red << "E: ", x << TermColor::def)
147 # define SHLOG_E_THROW(x) \
149 std::stringstream ss; \
151 std::string s{ ss.str() }; \
152 _write_log_err(TermColor::red << "E: ", s << TermColor::def); \
153 throw std::runtime_error{ ss.str() }; \
158 # define SHLOG_E_THROW(x)
159 # define _write_log_err(level, x)
163 # define SHLOG_W(x) _write_log_out(TermColor::yellow << "W: ", x << TermColor::def)
165 # define SHLOG_W(x) _dont_write_log_err
169 # define SHLOG_I(x) _write_log_out(TermColor::white << "I: ", x << TermColor::def)
170 # define SHLOG_S(x) _write_log_out(TermColor::green << "S: ", x << TermColor::def)
172 # define SHLOG_I(x) _dont_write_log_err
173 # define SHLOG_S(x) _dont_write_log_err
177 # define SHLOG_D(x) _write_log_out(TermColor::grey << "D: ", x << TermColor::def)
179 # define SHLOG_D(x) _dont_write_log_err
184 # define _write_API_log_d(id, x) \
186 [[maybe_unused]] auto static_logger_lck{ lock_out() }; \
187 std::cout << TermColor::blue << "--> [ " << (utils::timestamp() / 1000) << id << " ] " << TermColor::cyan \
192 # define _write_API_unlog_d(id, x) \
194 [[maybe_unused]] auto static_logger_lck{ lock_out() }; \
195 std::cout << TermColor::blue << "<-- [ " << (utils::timestamp() / 1000) << id << " ] " << TermColor::cyan \
200 # define SHLOG_REQ(id, x) _write_API_log_d(id, x)
201 # define SHLOG_UNREQ(id, x) _write_API_unlog_d(id, x)
203 # define SHLOG_REQ(id, x) _dont_write_log_err
204 # define SHLOG_UNREQ(id, x) _dont_write_log_err
210 #define do_assert(assertion, msg) \
212 if (!(assertion)) { \
213 std::cerr << "ASSERTION FAILED: " << msg << "\n\t" \
215 << "() in " << view_tail(__FILE__, FILE_NAME_TAIL_LEN) << " :" << __LINE__ << "" << std::endl; \
216 throw std::runtime_error("ASSERTION FAILED!"); \
221 #define do_assert_equals(a, b, msg) do_assert(a == b, msg);
225 #define do_assert_debug(assertion, msg) \
227 if constexpr (RUN_ASSERTS) { \
228 do_assert(assertion, msg); \
Definition: static-logger.hpp:71
Code code
Definition: static-logger.hpp:72
friend std::ostream & operator<<(std::ostream &os, const Modifier &mod)
Definition: static-logger.hpp:76
Modifier(Code pCode)
Definition: static-logger.hpp:75
Definition: static-logger.hpp:51
Code
Definition: static-logger.hpp:52
@ FG_YELLOW
Definition: static-logger.hpp:55
@ FG_DEFAULT
Definition: static-logger.hpp:60
@ BG_GREY
Definition: static-logger.hpp:68
@ FG_GREEN
Definition: static-logger.hpp:54
@ BG_CYAN
Definition: static-logger.hpp:66
@ BG_BLUE
Definition: static-logger.hpp:65
@ FG_RED
Definition: static-logger.hpp:53
@ FG_BLUE
Definition: static-logger.hpp:56
@ BG_RED
Definition: static-logger.hpp:62
@ BG_DEFAULT
Definition: static-logger.hpp:69
@ BG_YELLOW
Definition: static-logger.hpp:64
@ BG_GREEN
Definition: static-logger.hpp:63
@ FG_WHITE
Definition: static-logger.hpp:58
@ FG_CYAN
Definition: static-logger.hpp:57
@ FG_GREY
Definition: static-logger.hpp:59
@ BG_WHITE
Definition: static-logger.hpp:67
Definition: common-types.h:33
constexpr bool RUN_ASSERTS
If true the assertions will be executed.
Definition: static-logger.hpp:49
std::mutex logger_mtx
Mutex for optional STDOUT/STDERR synchronization.
Definition: static-logger.hpp:106