5#ifndef SAPPHIRE_LOGGER_LOG_MACRO_GUARD
6#define SAPPHIRE_LOGGER_LOG_MACRO_GUARD
10#include <SA/Support/Debug.hpp>
13#include <SA/Logger/Misc/StringFormat.hpp>
14#include <SA/Logger/Preprocessors/FileName.hpp>
15#include <SA/Logger/Preprocessors/FunctionName.hpp>
16#include <SA/Logger/Preprocessors/ChannelName.hpp>
17#include <SA/Logger/Preprocessors/Unparenthese.hpp>
61 void DefaultLogCallback(
SA::Log _log);
69 #define __SA_LOGGER(_log)\
70 if (SA::Debug::logger)\
71 SA::Debug::logger->Log(_log);\
72 else if (SA::Debug::logCB)\
73 SA::Debug::logCB(_log);\
75 std::cerr << "Try logging with invalid logger instance or callback! Initialize SA::Debug::logger or SA::Debug::logCB." << std::endl;
77 #define __SA_LOG_FRAME_NUM\
78 SA::Debug::logger ? SA::Debug::logger->GetFrameNum() : 0u
89 #define __SA_CREATE_LOG(_str, _lvl, _chan, _dets) SA::Log(\
93 SA::StringFormat(__SA_UNPARENT(_str)),\
95 __SA_CHAN_NAME(_chan),\
96 SA::StringFormat(__SA_UNPARENT(_dets)),\
103 #define __SA_SELECT_LOG_MACRO(_1, _2, _3, _4, _5, _name, ...) _name
105 #define __SA_LOG4(_str, _lvl, _chan, _dets) __SA_LOGGER(__SA_CREATE_LOG(_str, _lvl, _chan, _dets));
106 #define __SA_LOG5(_str, _lvl, _chan, _dets, _postCmd) { __SA_LOG4(_str, _lvl, _chan, _dets) _postCmd; }
107 #define __SA_LOG3(_str, _lvl, _chan) __SA_LOG4(_str, _lvl, _chan, L"")
108 #define __SA_LOG2(_str, _lvl) __SA_LOG3(_str, _lvl, Default)
109 #define __SA_LOG1(_str) __SA_LOG2(_str, Normal)
111 #define __SA_COND_LOG(_pred, _lvl, ...) if(!(_pred)) SA_LOG(L"{ " SA_WSTR(_pred) " }\tevaluated to false!", _lvl, ##__VA_ARGS__)
124 #define SA_LOG_END_OF_FRAME()
139 #define SA_LOG((_str, _args), _lvl, _chan, _dets)
153 #define SA_WARN(_pred, _chan, _dets, _postCmd)
167 #define SA_ERROR(_pred, _chan, _dets, _postCmd)
169#elif SA_DEBUG || SA_LOG_RELEASE_OPT
171 #define SA_LOG_END_OF_FRAME() { if(SA::Debug::logger) SA::Debug::logger->IncrementFrameNum(); }
173 #define SA_LOG(...) { __SA_SELECT_LOG_MACRO(__VA_ARGS__, __SA_LOG5, __SA_LOG4, __SA_LOG3, __SA_LOG2, __SA_LOG1)(__VA_ARGS__) }
175 #define SA_WARN(_pred, ...) { __SA_COND_LOG(_pred, Warning, ##__VA_ARGS__) }
177 #define SA_ERROR(_pred, ...) { __SA_COND_LOG(_pred, Error, ##__VA_ARGS__) }
181 #define SA_LOG_END_OF_FRAME() {}
183 #define SA_LOG(...) {}
185 #define SA_WARN(...) {}
187 #define SA_ERROR(...) {}
Log type implementation.
Definition Log.hpp:25
Logger base class implementation.
Definition LoggerBase.hpp:29
void InitDefaultLogger()
Initialize default logger for single-thread use. Console color and file output.
LoggerBase * logger
Logger instance.
void InitDefaultLoggerThread()
Initialize default logger for multi-thread use. Console color and file output.
void(* logCB)(SA::Log)
Simple logger callback.