From 26f0c1773249eb945fe4775a945ac3fe8d7f5e28 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 11 Jun 2022 15:27:52 +0200 Subject: [PATCH] Initial cleanup for the logger. --- core/log/error_macros.h | 93 -------------------------------------- core/log/logger.h | 98 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 95 insertions(+), 96 deletions(-) delete mode 100644 core/log/error_macros.h diff --git a/core/log/error_macros.h b/core/log/error_macros.h deleted file mode 100644 index 66b211477..000000000 --- a/core/log/error_macros.h +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef ERROR_MACROS_H -#define ERROR_MACROS_H - -#include "core/log/logger.h" -#include "core/typedefs.h" - -// template methods for the variadic log macros. Add more as needed. -template -_FORCE_INLINE_ void _RLOG_MACRO_TEMPLATE_FUNC(STR str, A p0) { - str->append(p0); -} - -template -_FORCE_INLINE_ void _RLOG_MACRO_TEMPLATE_FUNC(STR str, A p0, B p1) { - str->append(p0); - str->push_back(' '); - str->append(p1); -} - -template -_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 -_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 -_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 RPRINT_TRACE(str) \ - RLogger::print_trace(__FUNCTION__, __FILE__, __LINE__, str); - -#define RLOG_TRACE(...) \ - { \ - 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 RPRINT_MSG(str) \ - RLogger::print_message(__FUNCTION__, __FILE__, __LINE__, str); - -#define RLOG_MSG(...) \ - { \ - String *_rlogger_string_ptr = RLogger::get_message_string_ptr(__FUNCTION__, __FILE__, __LINE__); \ - _RLOG_MACRO_TEMPLATE_FUNC(_rlogger_string_ptr, __VA_ARGS__); \ - RLogger::log_ret_ptr(_rlogger_string_ptr); \ - } - -#define RPRINT_WARN(str) \ - RLogger::print_warning(__FUNCTION__, __FILE__, __LINE__, str); - -#define RLOG_WARN(...) \ - { \ - String *_rlogger_string_ptr = RLogger::get_warning_string_ptr(__FUNCTION__, __FILE__, __LINE__); \ - _RLOG_MACRO_TEMPLATE_FUNC(_rlogger_string_ptr, __VA_ARGS__); \ - RLogger::log_ret_ptr(_rlogger_string_ptr); \ - } - -#define RPRINT_ERR(str) \ - RLogger::print_error(__FUNCTION__, __FILE__, __LINE__, str); - -#define RLOG_ERR(...) \ - { \ - String *_rlogger_string_ptr = RLogger::get_error_string_ptr(__FUNCTION__, __FILE__, __LINE__); \ - _RLOG_MACRO_TEMPLATE_FUNC(_rlogger_string_ptr, __VA_ARGS__); \ - RLogger::log_ret_ptr(_rlogger_string_ptr); \ - } - -#endif diff --git a/core/log/logger.h b/core/log/logger.h index c45aa32a0..c9471a005 100644 --- a/core/log/logger.h +++ b/core/log/logger.h @@ -2,14 +2,16 @@ #ifndef LOGGER_H #define LOGGER_H +#include "core/reference.h" +#include "core/ustring.h" +#include "logger_backend.h" + #include #include -#include -#include class String; -class RLogger { +class RLogger : public Object { public: static void print_trace(const String &str); static void print_trace(const char *str); @@ -72,6 +74,96 @@ public: static void log_ptr(String *str); static void log_ret_ptr(String *str); + + Ref _backend; + + //func impl -> uif backend() -> call, else printf(). }; +// template methods for the variadic log macros. Add more as needed. +template +_FORCE_INLINE_ void _RLOG_MACRO_TEMPLATE_FUNC(STR str, A p0) { + str->append(p0); +} + +template +_FORCE_INLINE_ void _RLOG_MACRO_TEMPLATE_FUNC(STR str, A p0, B p1) { + str->append(p0); + str->push_back(' '); + str->append(p1); +} + +template +_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 +_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 +_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 RPRINT_TRACE(str) \ + RLogger::print_trace(__FUNCTION__, __FILE__, __LINE__, str); + +#define RLOG_TRACE(...) \ + { \ + 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 RPRINT_MSG(str) \ + RLogger::print_message(__FUNCTION__, __FILE__, __LINE__, str); + +#define RLOG_MSG(...) \ + { \ + String *_rlogger_string_ptr = RLogger::get_message_string_ptr(__FUNCTION__, __FILE__, __LINE__); \ + _RLOG_MACRO_TEMPLATE_FUNC(_rlogger_string_ptr, __VA_ARGS__); \ + RLogger::log_ret_ptr(_rlogger_string_ptr); \ + } + +#define RPRINT_WARN(str) \ + RLogger::print_warning(__FUNCTION__, __FILE__, __LINE__, str); + +#define RLOG_WARN(...) \ + { \ + String *_rlogger_string_ptr = RLogger::get_warning_string_ptr(__FUNCTION__, __FILE__, __LINE__); \ + _RLOG_MACRO_TEMPLATE_FUNC(_rlogger_string_ptr, __VA_ARGS__); \ + RLogger::log_ret_ptr(_rlogger_string_ptr); \ + } + +#define RPRINT_ERR(str) \ + RLogger::print_error(__FUNCTION__, __FILE__, __LINE__, str); + +#define RLOG_ERR(...) \ + { \ + String *_rlogger_string_ptr = RLogger::get_error_string_ptr(__FUNCTION__, __FILE__, __LINE__); \ + _RLOG_MACRO_TEMPLATE_FUNC(_rlogger_string_ptr, __VA_ARGS__); \ + RLogger::log_ret_ptr(_rlogger_string_ptr); \ + } + #endif