commore  1.0.6-SNAPSHOT
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Error.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2006-2014 Raphael David / CANTOR
3 //
4 
5 #ifndef CMR_LOG_INCLUDED
6 #define CMR_LOG_INCLUDED
7 
8 #include "Commore.h"
9 #include "GlobVar.h"
10 
11 namespace commore
12 {
16  enum LOG_LEVEL
17  {
25  };
26 
27 }
28 
29 namespace commore
30 {
35  class CMREXD Log
36  {
37  public:
45  Log(const AChar* key,
46  LOG_LEVEL level,
47  const AChar* module_name,
48  const AChar* unit_name, int line);
52  ~Log();
53 
54  public:
58  void add(const char* a);
62  void add(const void* a);
66  void add(int);
70  void add(double);
74  void add(bool);
75 
83  commore::Log& operator << (unsigned char c);
87  commore::Log& operator << (const unsigned char* s);
95  commore::Log& operator << (const void* s);
99  commore::Log& operator << (short i);
108  commore::Log& operator << (long i);
117  commore::Log& operator << (unsigned short i);
121  commore::Log& operator << (unsigned int i);
126  commore::Log& operator << (unsigned long i);
130  commore::Log& operator << (float i);
134  commore::Log& operator << (double i);
138  commore::Log& operator << (bool i);
187  // commore::Log& operator << (const commore::String& t);
196 
217 
250 
255  static const AString& toString(Double val, AString& dst);
260  static const AString& toString(Float val, AString& dst);
265  static const AString& toString(Long val, AString& dst);
270  static const AString& toString(Int val, AString& dst);
275  static const AString& toString(Bool val, AString& dst);
276 
277  private:
281  LOG_LEVEL level_;
285  const AChar* key_;
286  const AChar* module_name_;
287  const AChar* unit_name_;
291  int line_;
292  struct Arg;
296  Arg* args_;
297  };
298 }
299 
300 
305 #define CMR_LOG(msg) if (cmr_log_flag.get() > 0) commore::Log(msg, commore::ERR_LOG, cmr_log_flag.get_module(), cmr_log_flag.get_name(), __LINE__)
306 #define CMR_LOG2(msg) if (cmr_log_flag.get() > 1) commore::Log(msg, commore::ERR_LOG, cmr_log_flag.get_module(), cmr_log_flag.get_name(), __LINE__)
311 #define CMR_LOG3(msg) if (cmr_log_flag.get() > 2) commore::Log(msg, commore::ERR_LOG, cmr_log_flag.get_module(), cmr_log_flag.get_name(), __LINE__)
316 
321 #define CMR_DLOG(msg) commore::Log(msg, commore::ERR_LOG, cmr_log_flag.get_module(), cmr_log_flag.get_name(), __LINE__)
322 #define CMR_DLOG2(msg) commore::Log(msg, commore::ERR_LOG, cmr_log_flag.get_module(), cmr_log_flag.get_name(), __LINE__)
327 #define CMR_DLOG3(msg) commore::Log(msg, commore::ERR_LOG, cmr_log_flag.get_module(), cmr_log_flag.get_name(), __LINE__)
332 
337 #define CMR_INFO(msg) commore::Log(msg, commore::ERR_INFO, cmr_log_flag.get_module(), cmr_log_flag.get_name(), __LINE__)
338 #ifdef _DEBUG
343 #define CMR_DEBUG(msg) commore::Log(msg, commore::ERR_DEBUG, cmr_log_flag.get_module(), cmr_log_flag.get_name(), __LINE__)
344 #else
345 #define CMR_DEBUG(msg) if (cmr_log_flag.get() > 1) commore::Log(msg, commore::ERR_DEBUG, cmr_log_flag.get_module(), cmr_log_flag.get_name(), __LINE__)
346 #endif
347 
352 #define CMR_ERROR(msg) commore::Log(msg, commore::ERR_ERROR, cmr_log_flag.get_module(), cmr_log_flag.get_name(), __LINE__)
353 #define CMR_WARNING(msg) commore::Log(msg, commore::ERR_WARNING, cmr_log_flag.get_module(), cmr_log_flag.get_name(), __LINE__)
358 
359 
363 #define CMR_LOG_DECLARE(name) static commore::GlobVarLog& cmr_log_flag_##name() { static commore::GlobVarLog r(CMR_MODULE_NAME, #name); return r; }
364 #define CMR_CHECK_NLOG(n,level) (cmr_log_flag_##n().get() > level)
368 
374 #define CMR_NLOG(n,msg) if (CMR_CHECK_NLOG(n,0)) commore::Log(msg, commore::ERR_LOG, cmr_log_flag_##n().get_module(), cmr_log_flag_##n().get_name(), __LINE__)
375 #define CMR_NLOG2(n,msg) if (CMR_CHECK_NLOG(n,1)) commore::Log(msg, commore::ERR_LOG, cmr_log_flag_##n().get_module(), cmr_log_flag_##n().get_name(), __LINE__)
381 #define CMR_NLOG3(n,msg) if (CMR_CHECK_NLOG(n,2)) commore::Log(msg, commore::ERR_LOG, cmr_log_flag_##n().get_module(), cmr_log_flag_##n().get_name(), __LINE__)
387 #define CMR_NLOG4(n,msg) if (CMR_CHECK_NLOG(n,3)) commore::Log(msg, commore::ERR_LOG, cmr_log_flag##n().get_module(), cmr_log_flag##n().get_name(), __LINE__)
393 
394 
395 
396 
397 
398 
399 #endif
400 
Definition: Error.h:21
Definition: Error.h:23
Definition: Tuple.h:29
Definition: AString.h:39
bool Bool
Definition: Type.h:35
Definition: Time.h:21
Definition: List.h:23
Definition: Blob.h:18
Definition: StringBuffer.h:21
Definition: Error.h:19
double Double
Definition: Type.h:46
Definition: Symbol.h:18
char AChar
Definition: Type.h:65
Definition: Error.h:20
#define CMREXD
Definition: Compiler.h:22
LOG_LEVEL
Definition: Error.h:16
Definition: Error.h:24
Definition: Error.h:35
Definition: Error.h:22
int Int
Definition: Type.h:37
Definition: Array.h:21
Definition: Log.cpp:33
Definition: Error.h:18
float Float
Definition: Type.h:45
long long Long
Definition: Type.h:43
Definition: Time.h:261
CMREXD commore::OBStream & operator<<(commore::OBStream &o, const commore::AString &s)
Definition: AString.cpp:19