Concordia
logging.hpp
1 #ifndef LOGGING_HDR
2 #define LOGGING_HDR
3 
4 #include <log4cpp/Category.hh>
5 #include <log4cpp/OstreamAppender.hh>
6 #include <log4cpp/SimpleLayout.hh>
7 #include <log4cpp/Priority.hh>
8 
9 #include <iostream>
10 #include <sstream>
11 
12 #include "concordia/common/config.hpp"
13 
18 public:
22 
26 
30  void setLoggingToFile(const std::string & filepath);
31 
35  void setLoggingPriority(const std::string & priorityName);
36 
40  log4cpp::Priority::Value getLoggingPriority();
41 
45  void flush(log4cpp::Priority::Value priorityLevel);
46 
50  ConcordiaLogger & operator<< (const std::string & msg);
51 
55  ConcordiaLogger & operator<< (const char * msg);
56 
60  ConcordiaLogger & operator<< (unsigned long msg);
61 
65  ConcordiaLogger & operator<< (signed long msg);
66 
70  ConcordiaLogger & operator<< (unsigned int msg);
71 
75  ConcordiaLogger & operator<< (signed int msg);
76 
80  ConcordiaLogger & operator<< (unsigned short msg);
81 
85  ConcordiaLogger & operator<< (signed short msg);
86 
90  ConcordiaLogger & operator<< (float msg);
91 
95  ConcordiaLogger & operator<< (double msg);
96 
100  ConcordiaLogger & operator<< (bool msg);
101 
102 private:
103  void initialize_logger_();
104  void setDefaultLoggerAppender_();
105  void addDefaultLayoutToAppender_(log4cpp::Appender * appender);
106  void setNewLoggerAppender_(log4cpp::Appender * appender);
107 
108  std::stringstream buffer;
109  log4cpp::Category & logger_category;
110  log4cpp::Appender * current_logger_appender;
111 };
112 
113 extern ConcordiaLogger concordia_logger;
114 
115 #define TRACE(M) \
116  do { \
117  concordia_logger << M; \
118  concordia_logger.flush(log4cpp::Priority::DEBUG); \
119  } while (0)
120 
121 #define DEBUG(M) \
122  do { \
123  concordia_logger << M; \
124  concordia_logger.flush(log4cpp::Priority::DEBUG); \
125  } while (0)
126 
127 #define DEBUG_NOFLUSH(M) \
128  do { \
129  concordia_logger << M; \
130  } while (0)
131 
132 #define FLUSH \
133  do { \
134  concordia_logger.flush(log4cpp::Priority::DEBUG); \
135  } while (0)
136 
137 #define INFO(M) \
138  do { \
139  concordia_logger << M; \
140  concordia_logger.flush(log4cpp::Priority::INFO); \
141  } while (0)
142 
143 #define WARN(M) \
144  do { \
145  concordia_logger << M; \
146  concordia_logger.flush(log4cpp::Priority::WARN); \
147  } while (0)
148 
149 #define ERROR(M) \
150  do { \
151  concordia_logger << M; \
152  concordia_logger.flush(log4cpp::Priority::ERROR); \
153  } while (0)
154 
155 #define FATAL(M) \
156  do { \
157  concordia_logger << M; \
158  concordia_logger.flush(log4cpp::Priority::FATAL); \
159  } while (0)
160 
161 
162 #define SET_LOGGER_FILE(M) do { concordia_logger.setLoggingToFile(M); \
163  } while (0);
164 #define SET_LOGGING_LEVEL(M) \
165  do { concordia_logger.setLoggingPriority(M); } while (0);
166 #endif
void setLoggingPriority(const std::string &priorityName)
Definition: logging.cpp:49
log4cpp::Priority::Value getLoggingPriority()
Definition: logging.cpp:59
ConcordiaLogger()
Definition: logging.cpp:8
void setLoggingToFile(const std::string &filepath)
Definition: logging.cpp:42
Definition: logging.hpp:17
void flush(log4cpp::Priority::Value priorityLevel)
Definition: logging.cpp:70
~ConcordiaLogger()
Definition: logging.cpp:39
ConcordiaLogger & operator<<(const std::string &msg)
Definition: logging.cpp:75