Added variadic macros to be used with the new stream like logging api.

This commit is contained in:
Relintai 2022-02-15 12:49:21 +01:00
parent 94b9948199
commit a111150e7e

View File

@ -2,13 +2,13 @@
#define ERROR_MACROS_H #define ERROR_MACROS_H
#include "core/log/logger.h" #include "core/log/logger.h"
#include "typedefs.h"
// Based on Godot Engine's error_macros.h // Based on Godot Engine's error_macros.h
// MIT License // MIT License
// Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. // Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.
// Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). // Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md).
#ifdef _MSC_VER #ifdef _MSC_VER
#define GENERATE_TRAP \ #define GENERATE_TRAP \
__debugbreak(); \ __debugbreak(); \
@ -19,124 +19,198 @@
#define GENERATE_TRAP __builtin_trap(); #define GENERATE_TRAP __builtin_trap();
#endif #endif
// template methods for the variadic log macros. Add more as needed.
template <class STR, class A>
_FORCE_INLINE_ void _RLOG_MACRO_TEMPLATE_FUNC(STR str, A p0) {
str->append(p0);
}
template <class STR, class A, class B>
_FORCE_INLINE_ void _RLOG_MACRO_TEMPLATE_FUNC(STR str, A p0, B p1) {
str->append(p0);
str->push_back(' ');
str->append(p1);
}
template <class STR, class A, class B, class C>
_FORCE_INLINE_ void _RLOG_MACRO_TEMPLATE_FUNC(STR str, A p0, B p1, C p2) {
str->append(p0);
str->push_back(' ');
str->append(p1);
str->push_back(' ');
str->append(p2);
}
template <class STR, class A, class B, class C, class D>
_FORCE_INLINE_ void _RLOG_MACRO_TEMPLATE_FUNC(STR str, A p0, B p1, C p2, D p3) {
str->append(p0);
str->push_back(' ');
str->append(p1);
str->push_back(' ');
str->append(p2);
str->push_back(' ');
str->append(p3);
}
template <class STR, class A, class B, class C, class D, class E>
_FORCE_INLINE_ void _RLOG_MACRO_TEMPLATE_FUNC(STR str, A p0, B p1, C p2, D p3, E p4) {
str->append(p0);
str->push_back(' ');
str->append(p1);
str->push_back(' ');
str->append(p2);
str->push_back(' ');
str->append(p3);
str->push_back(' ');
str->append(p4);
}
#define RLOG_TRACE(str) \ #define RLOG_TRACE(str) \
RLogger::log_trace(__FUNCTION__, __FILE__, __LINE__, str); RLogger::log_trace(__FUNCTION__, __FILE__, __LINE__, str);
#define RLOG_TRACEP(...) \
{ \
String *_rlogger_string_ptr = RLogger::get_trace_string_ptr(__FUNCTION__, __FILE__, __LINE__); \
_RLOG_MACRO_TEMPLATE_FUNC(_rlogger_string_ptr, __VA_ARGS__); \
RLogger::log_ret_ptr(_rlogger_string_ptr); \
}
#define RLOG_MSG(str) \ #define RLOG_MSG(str) \
RLogger::log_message(__FUNCTION__, __FILE__, __LINE__, str); RLogger::log_message(__FUNCTION__, __FILE__, __LINE__, str);
#define RLOG_MSGP(...) \
{ \
String *_rlogger_string_ptr = RLogger::get_trace_string_ptr(__FUNCTION__, __FILE__, __LINE__); \
_RLOG_MACRO_TEMPLATE_FUNC(_rlogger_string_ptr, __VA_ARGS__); \
RLogger::log_ret_ptr(_rlogger_string_ptr); \
}
#define RLOG_WARN(str) \ #define RLOG_WARN(str) \
RLogger::log_warning(__FUNCTION__, __FILE__, __LINE__, str); RLogger::log_warning(__FUNCTION__, __FILE__, __LINE__, str);
#define RLOG_WARNP(...) \
{ \
String *_rlogger_string_ptr = RLogger::get_trace_string_ptr(__FUNCTION__, __FILE__, __LINE__); \
_RLOG_MACRO_TEMPLATE_FUNC(_rlogger_string_ptr, __VA_ARGS__); \
RLogger::log_ret_ptr(_rlogger_string_ptr); \
}
#define RLOG_ERR(str) \ #define RLOG_ERR(str) \
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, str); RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, str);
#define ERR_FAIL_MSG(msg) \ #define RLOG_ERRP(...) \
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, msg); \ { \
return; String *_rlogger_string_ptr = RLogger::get_trace_string_ptr(__FUNCTION__, __FILE__, __LINE__); \
_RLOG_MACRO_TEMPLATE_FUNC(_rlogger_string_ptr, __VA_ARGS__); \
RLogger::log_ret_ptr(_rlogger_string_ptr); \
}
#define ERR_FAIL_V_MSG(val, msg) \ #define ERR_FAIL_MSG(msg) \
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, msg); \ RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, msg); \
return val; return;
#define ERR_FAIL_INDEX(index, size) \ #define ERR_FAIL_V_MSG(val, msg) \
if ((index < 0) || (index >= size)) {\ RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, msg); \
RLogger::log_index_error(__FUNCTION__, __FILE__, __LINE__, index, size, ""); \ return val;
return;\
} else\
((void)0)\
#define ERR_FAIL_INDEX_MSG(index, size, msg) \ #define ERR_FAIL_INDEX(index, size) \
if ((index < 0) || (index >= size)) {\ if ((index < 0) || (index >= size)) { \
RLogger::log_index_error(__FUNCTION__, __FILE__, __LINE__, index, size, msg); \ RLogger::log_index_error(__FUNCTION__, __FILE__, __LINE__, index, size, ""); \
return;\ return; \
} else\ } else \
((void)0)\ ((void)0)
#define ERR_FAIL_INDEX_V(index, size, val) \ #define ERR_FAIL_INDEX_MSG(index, size, msg) \
if ((index < 0) || (index >= size)) {\ if ((index < 0) || (index >= size)) { \
RLogger::log_index_error(__FUNCTION__, __FILE__, __LINE__, index, size, ""); \ RLogger::log_index_error(__FUNCTION__, __FILE__, __LINE__, index, size, msg); \
return val;\ return; \
} else\ } else \
((void)0)\ ((void)0)
#define ERR_FAIL_INDEX_V_MSG(index, size, val, msg) \ #define ERR_FAIL_INDEX_V(index, size, val) \
if ((index < 0) || (index >= size)) {\ if ((index < 0) || (index >= size)) { \
RLogger::log_index_error(__FUNCTION__, __FILE__, __LINE__, index, size, msg); \ RLogger::log_index_error(__FUNCTION__, __FILE__, __LINE__, index, size, ""); \
return val;\ return val; \
} else\ } else \
((void)0)\ ((void)0)
#define ERR_FAIL_COND(cond) \ #define ERR_FAIL_INDEX_V_MSG(index, size, val, msg) \
if (cond) {\ if ((index < 0) || (index >= size)) { \
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, "ERR_FAIL_COND: \"" #cond "\" is true!"); \ RLogger::log_index_error(__FUNCTION__, __FILE__, __LINE__, index, size, msg); \
return;\ return val; \
} else\ } else \
((void)0)\ ((void)0)
#define ERR_FAIL_COND_MSG(cond, msg) \ #define ERR_FAIL_COND(cond) \
if (cond) {\ if (cond) { \
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, msg); \ RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, "ERR_FAIL_COND: \"" #cond "\" is true!"); \
return;\ return; \
} else\ } else \
((void)0)\ ((void)0)
#define ERR_FAIL_COND_V(cond, val) \ #define ERR_FAIL_COND_MSG(cond, msg) \
if (cond) {\ if (cond) { \
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, "ERR_FAIL_COND: \"" #cond "\" is true!"); \ RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, msg); \
return val;\ return; \
} else\ } else \
((void)0)\ ((void)0)
#define ERR_FAIL_COND_V_MSG(cond, val, msg) \ #define ERR_FAIL_COND_V(cond, val) \
if (cond) {\ if (cond) { \
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, msg); \ RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, "ERR_FAIL_COND: \"" #cond "\" is true!"); \
return val;\ return val; \
} else\ } else \
((void)0)\ ((void)0)
#define ERR_CONTINUE(cond) \ #define ERR_FAIL_COND_V_MSG(cond, val, msg) \
if (cond) {\ if (cond) { \
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, "ERR_CONTINUE: \"" #cond "\" is true!"); \ RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, msg); \
continue;\ return val; \
} else\ } else \
((void)0)\ ((void)0)
#define ERR_CONTINUE_MSG(cond, msg) \ #define ERR_CONTINUE(cond) \
if (cond) {\ if (cond) { \
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, msg); \ RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, "ERR_CONTINUE: \"" #cond "\" is true!"); \
continue;\ continue; \
} else\ } else \
((void)0)\ ((void)0)
#define ERR_CONTINUE_ACTION(cond, action) \ #define ERR_CONTINUE_MSG(cond, msg) \
if (cond) {\ if (cond) { \
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, "ERR_CONTINUE: \"" #cond "\" is true!"); \ RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, msg); \
action;\ continue; \
continue;\ } else \
} else\ ((void)0)
((void)0)\
#define ERR_CONTINUE_ACTION_MSG(cond, action, msg) \ #define ERR_CONTINUE_ACTION(cond, action) \
if (cond) {\ if (cond) { \
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, msg); \ RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, "ERR_CONTINUE: \"" #cond "\" is true!"); \
action;\ action; \
continue;\ continue; \
} else\ } else \
((void)0)\ ((void)0)
#define CRASH_INDEX(index, size) \ #define ERR_CONTINUE_ACTION_MSG(cond, action, msg) \
if ((index < 0) || (index >= size)) {\ if (cond) { \
RLogger::log_index_error(__FUNCTION__, __FILE__, __LINE__, index, size, "CRASH!"); \ RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, msg); \
GENERATE_TRAP \ action; \
} else\ continue; \
((void)0)\ } else \
((void)0)
#define CRASH_COND(cond) \ #define CRASH_INDEX(index, size) \
if (cond) {\ if ((index < 0) || (index >= size)) { \
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, "CRASH_COND: \"" #cond "\" is true!"); \ RLogger::log_index_error(__FUNCTION__, __FILE__, __LINE__, index, size, "CRASH!"); \
GENERATE_TRAP \ GENERATE_TRAP \
} else\ } else \
((void)0)\ ((void)0)
#define CRASH_COND(cond) \
if (cond) { \
RLogger::log_error(__FUNCTION__, __FILE__, __LINE__, "CRASH_COND: \"" #cond "\" is true!"); \
GENERATE_TRAP \
} else \
((void)0)
#endif #endif