MADARA  3.1.8
LogMacros.h
Go to the documentation of this file.
1 
16 #ifndef _MADARA_LOG_MACROS_H_
17 #define _MADARA_LOG_MACROS_H_
18 
19 #include "MADARA_Logger_export.h"
20 #include "ace/Log_Msg.h"
21 
22 #ifdef _MADARA_ANDROID_
23 #include <android/log.h>
24 #endif
25 
26 #if !defined (DLINFO)
27 # define DLINFO ACE_TEXT("(%P|%t) [%M] - %T - ")
28 #endif
29 
31 
32 // Defines for logging levels
33 
36 #define MADARA_LOG_EMERGENCY 0
37 #define MADARA_LOG_TERMINAL_ERROR 1
41 #define MADARA_LOG_NONFATAL_ERROR 2
44 #define MADARA_LOG_ERROR 3
46 #define MADARA_LOG_WARNING 4
49 #define MADARA_LOG_MAJOR_EVENT 5
51 #define MADARA_LOG_MINOR_EVENT 6
53 #define MADARA_LOG_EVENT_TRACE 7
56 #define MADARA_LOG_MAJOR_DEBUG_INFO 8
59 #define MADARA_LOG_TRACE 9
65 #define MADARA_LOG_DETAILED_TRACE 10
66 
67 // By default tracing is turned off.
68 #if !defined (MADARA_NTRACE)
69 # define MADARA_NTRACE 1
70 #endif /* MADARA_NTRACE */
71 
72 #if (MADARA_NTRACE == 1)
73 # if !defined (ACE_NTRACE)
74 # define MADARA_TRACE(X) do {} while (0)
75 # define MADARA_ENABLE_TRACE() do {} while (0)
76 # define MADARA_DISABLE_TRACE() do {} while (0)
77 # else
78 # if (ACE_NTRACE == 0)
79 # error MADARA_TRACE cannot be disabled if ACE_TRACE is enabled
80 # else
81 # define MADARA_TRACE(X) do {} while (0)
82 # define MADARA_ENABLE_TRACE() do {} while (0)
83 # define MADARA_DISABLE_TRACE() do {} while (0)
84 # endif
85 # endif
86 #else
87 # if !defined (ACE_HAS_TRACE)
88 # define ACE_HAS_TRACE
89 # endif /* ACE_HAS_TRACE */
90 # define MADARA_TRACE(X) ACE_TRACE_IMPL (X)
91 # define MADARA_ENABLE_TRACE() ACE_Trace::start_tracing ()
92 # define MADARA_DISABLE_TRACE() ACE_Trace::stop_tracing ()
93 # undef DLINFO // Make log messages indent with tracing.
94 # define DLINFO ACE_TEXT("%I(%P|%t) [%M] - %T - ")
95 # include "ace/Trace.h"
96 #endif /* MADARA_NTRACE */
97 
98 #if defined (MADARA_NLOGGING)
99 # define MADARA_ERROR(L, X) do {} while (0)
100 # define MADARA_DEBUG(L, X) do {} while (0)
101 #define MADARA_ERROR_RETURN(L, X, Y) return (Y)
102 #define MADARA_ERROR_BREAK(L, X) { break; }
103 #else
104 #if !defined (MADARA_ERROR)
105  //#ifdef _MADARA_ANDROID_
106  //#define MADARA_ERROR(L, X) \
107  //do { \
108  // if (MADARA_debug_level >= L) \
109  // { \
110  // __android_log_print (ANDROID_LOG_ERROR, "MADARA", X); \
111  // } \
112  //} while (0)
113  //#else
114  #define MADARA_ERROR(L, X) \
115  do { \
116  if (MADARA_debug_level >= L) \
117  { \
118  int const __ace_error = ACE_Log_Msg::last_error_adapter (); \
119  ACE_Log_Msg *ace___ = ACE_Log_Msg::instance (); \
120  ace___->conditional_set (__FILE__, __LINE__, -1, __ace_error); \
121  ace___->log X; \
122  } \
123  } while (0)
124  //#endif
125 #endif
126 
127 # if !defined (MADARA_DEBUG)
128 //#ifdef _MADARA_ANDROID_
129 //#define MADARA_DEBUG(L, X) \
130 // do { \
131 // if (MADARA_debug_level >= L) \
132 // { \
133 // __android_log_print (ANDROID_LOG_INFO, "MADARA", X); \
134 // } \
135 // } while (0)
136 //#else
137 # define MADARA_DEBUG(L, X) \
138  do { \
139  if (MADARA_debug_level >= L) \
140  { \
141  int const __ace_error = ACE_Log_Msg::last_error_adapter (); \
142  ACE_Log_Msg *ace___ = ACE_Log_Msg::instance (); \
143  ace___->conditional_set (__FILE__, __LINE__, 0, __ace_error); \
144  ace___->log X; \
145  } \
146  } while (0)
147 //#endif
148 # endif
149 # if !defined (MADARA_LOG_TRACE)
150 # define MADARA_LOG_TRACE(L, X) \
151  do { \
152  if (MADARA_debug_level >= L) \
153  { \
154  int const __ace_error = ACE_Log_Msg::last_error_adapter (); \
155  ACE_Log_Msg *ace___ = ACE_Log_Msg::instance (); \
156  ace___->conditional_set (__FILE__, __LINE__, 0, __ace_error); \
157  ace___->log X; \
158  } \
159  } while (0)
160 # endif
161 # if !defined (MADARA_ERROR_RETURN)
162 # define MADARA_ERROR_RETURN(L, X, Y) \
163  do { \
164  if (MADARA_debug_level >= L) \
165  { \
166  int const __ace_error = ACE_Log_Msg::last_error_adapter (); \
167  ACE_Log_Msg *ace___ = ACE_Log_Msg::instance (); \
168  ace___->conditional_set (__FILE__, __LINE__, Y, __ace_error); \
169  ace___->log X; \
170  return Y; \
171  } \
172  } while (0)
173 # endif
174 # if !defined (MADARA_ERROR_BREAK)
175 # define MADARA_ERROR_BREAK(L, X) { MADARA_ERROR (L, X); break; }
176 # endif
177 #endif
178 
179 namespace madara
180 {
181  namespace utility
182  {
187  {
199  };
200 
205  inline void set_log_level (int level)
206  {
207  ::MADARA_debug_level = level;
208  }
209 
214  inline int get_log_level (void)
215  {
217  }
218 
224  inline void log (int level, const char * message)
225  {
226  MADARA_DEBUG (level, (LM_DEBUG, message));
227  }
228  }
229 }
230 
231 #endif // _MADARA_LOG_MACROS_H_
#define MADARA_Logger_Export
ACE_Proper_Import_Flag int MADARA_debug_level
Definition: LogMacros.cpp:5
void set_log_level(int level)
Sets the log level.
Definition: LogMacros.h:205
int get_log_level(void)
Gets the log level.
Definition: LogMacros.h:214
#define MADARA_DEBUG(L, X)
Definition: LogMacros.h:137
Provides utility functions and classes for common tasks and needs.
Definition: IteratorImpl.h:14
LogLevels
Logging levels available for MADARA library.
Definition: LogMacros.h:186
Copyright (c) 2015 Carnegie Mellon University.
void log(int level, const char *message)
Logs a simple string message.
Definition: LogMacros.h:224