UGDK  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
log.h
Go to the documentation of this file.
1 #ifndef UGDK_DEBUG_LOG_H_
2 #define UGDK_DEBUG_LOG_H_
3 
4 #include <string>
5 #include <sstream>
6 
7 namespace ugdk {
8 namespace debug {
9 
11 #define LOG_LEVELS(ACTION) \
12  ACTION(EMERGENCY) \
13  ACTION(ALERT) \
14  ACTION(CRITICAL) \
15  ACTION(ERROR) \
16  ACTION(WARNING) \
17  ACTION(NOTICE) \
18  ACTION(INFO)
19  //ACTION(DEBUG)
20 
22 #define LIST(X) X,
23 enum LogLevel {
25 };
26 #undef LIST
27 
28 // Even more Macro Wizardry(tm).
32 #define CASE_LOG(X) case X: return #X;
33 inline const char* ConvertLogToString(LogLevel level) {
34  switch(level) {
36  default: return "";
37  }
38 }
39 #undef CASE_LOG
40 
41 void RawLog(LogLevel, const std::string& owner, const std::string& message);
42 
43 #ifndef SWIG
44 inline void InsertToStream(std::stringstream& ss) {}
45 
46 template<typename T, typename... Ts>
47 inline void InsertToStream(std::stringstream& ss, const T& t, Ts&&... ts) {
48  ss << t;
49  InsertToStream(ss, std::forward<Ts>(ts)...);
50 }
51 
52 template<typename... Ts>
53 void Log(LogLevel level, const std::string& owner, Ts&&... ts) {
54  std::stringstream ss;
55  InsertToStream(ss, std::forward<Ts>(ts)...);
56  RawLog(level, owner, ss.str());
57 }
58 
59 template<typename... Ts>
60 inline void DebugLog(LogLevel level, const std::string& owner, Ts&&... ts) {
61 #ifndef NDEBUG
62  Log(level, owner, std::forward<Ts>(ts)...);
63 #endif
64 }
65 
67 
71 template<typename... Ts>
72 inline void DebugConditionalLog(bool assertion, LogLevel level, const std::string& owner, Ts&&... ts) {
73 #ifndef NDEBUG
74  if (!assertion)
75  Log(level, owner, std::forward<Ts>(ts)...);
76 #endif
77 }
78 
79 #endif // SWIG
80 
81 } // namespace debug
82 } // namespace ugdk
83 
84 #endif // UGDK_DEBUG_LOG_H_
#define LIST(X)
Through macro wizardy(tm), fill the LogLevel enum.
Definition: log.h:22
void DebugConditionalLog(bool assertion, LogLevel level, const std::string &owner, Ts &&...ts)
If assertion is false, run the DebugLog command.
Definition: log.h:72
LogLevel
Definition: log.h:23
void InsertToStream(std::stringstream &ss)
Definition: log.h:44
void DebugLog(LogLevel level, const std::string &owner, Ts &&...ts)
Definition: log.h:60
void Log(LogLevel level, const std::string &owner, Ts &&...ts)
Definition: log.h:53
Definition: animation.h:11
#define LOG_LEVELS(ACTION)
These are the log levels.
Definition: log.h:11
void RawLog(LogLevel, const std::string &owner, const std::string &message)
#define CASE_LOG(X)
Definition: log.h:32
const char * ConvertLogToString(LogLevel level)
Definition: log.h:33