ESA JPIP server  0.1
trace.h
Go to the documentation of this file.
1 #ifndef _TRACE_H_
2 #define _TRACE_H_
3 
4 
5 #include <string>
6 #include <iostream>
7 
8 #define LOG4CPP_FIX_ERROR_COLLISION 1
9 #include <log4cpp/Category.hh>
10 #include <log4cpp/FileAppender.hh>
11 #include <log4cpp/PatternLayout.hh>
12 #include <log4cpp/OstreamAppender.hh>
13 
14 
20 {
21 private:
22  log4cpp::Category *category;
23  log4cpp::Appender *appender;
24  log4cpp::PatternLayout *layout;
25  log4cpp::Appender *file_appender;
26  log4cpp::PatternLayout *file_layout;
27 
29 
30  TraceSystem();
31  virtual ~TraceSystem();
32 
33  bool AppendToFile_(const char *name);
34 
35 public:
36  static bool AppendToFile(const char *name)
37  {
38  return traceSystem.AppendToFile_(name);
39  }
40 
41  static bool AppendToFile(const std::string& name)
42  {
43  return traceSystem.AppendToFile_(name.c_str());
44  }
45 
46  static log4cpp::CategoryStream logStream()
47  {
48  return traceSystem.category->infoStream();
49  }
50 
51  static log4cpp::CategoryStream errorStream()
52  {
53  return traceSystem.category->errorStream();
54  }
55 
56  static log4cpp::CategoryStream traceStream()
57  {
58  return traceSystem.category->debugStream();
59  }
60 };
61 
62 
63 #define _RED "31m"
64 #define _GREEN "32m"
65 #define _YELLOW "33m"
66 #define _BLUE "34m"
67 
68 #ifndef NO_COLORS
69 #define _SET_COLOR(a) "\033[" a
70 #define _RESET_COLOR() "\033[0m"
71 #else
72 #define _SET_COLOR(a) ""
73 #define _RESET_COLOR() ""
74 #endif
75 
76 #ifndef SILENT_MODE
77 #define LOG(a) (TraceSystem::logStream() << a << log4cpp::eol)
78 #define LOGC(c, a) (TraceSystem::logStream() << _SET_COLOR(c) << a << _RESET_COLOR() << log4cpp::eol)
79 #define ERROR(a) (TraceSystem::errorStream() << _SET_COLOR(_RED) << __FILE__ << ":" << __LINE__ << ": ERROR: " << a << _RESET_COLOR() << log4cpp::eol)
80 #else
81 #define LOG(a) {}
82 #define LOGC(c, a) {}
83 #define ERROR(a) {}
84 #endif
85 
86 #if defined(SHOW_TRACES) && !defined(NDEBUG) && !defined(SILENT_MODE)
87 #define TRACE(a) (TraceSystem::traceStream() << _SET_COLOR(_YELLOW) << __FILE__ << ":" << __LINE__ << ": TRACE: " << a << _RESET_COLOR() << log4cpp::eol)
88 #else
89 #define TRACE(a) {}
90 #endif
91 
92 #define CERR(a) (cerr << _SET_COLOR(_RED) << a << "!" << _RESET_COLOR() << endl, -1)
93 
94 #endif
log4cpp::Appender * appender
Definition: trace.h:23
static TraceSystem traceSystem
Definition: trace.h:28
static log4cpp::CategoryStream errorStream()
Definition: trace.h:51
static bool AppendToFile(const char *name)
Definition: trace.h:36
static bool AppendToFile(const std::string &name)
Definition: trace.h:41
log4cpp::Appender * file_appender
Definition: trace.h:25
bool AppendToFile_(const char *name)
Definition: trace.cc:27
TraceSystem()
Definition: trace.cc:10
Wrapper used by the application to handle the log/trace messages by means of the log4cpp library...
Definition: trace.h:19
static log4cpp::CategoryStream logStream()
Definition: trace.h:46
log4cpp::PatternLayout * layout
Definition: trace.h:24
virtual ~TraceSystem()
Definition: trace.cc:64
log4cpp::PatternLayout * file_layout
Definition: trace.h:26
log4cpp::Category * category
Definition: trace.h:22
static log4cpp::CategoryStream traceStream()
Definition: trace.h:56