43 template <
typename T>
class Log
71 return reportingLevel;
77 inline static std::string
ToString(
const int level) {
78 static const char*
const buffer[] = {
98 if (level ==
"DEBUG4")
100 if (level ==
"DEBUG3")
102 if (level ==
"DEBUG2")
104 if (level ==
"DEBUG1")
106 if (level ==
"DEBUG")
110 if (level ==
"WARNING")
112 if (level ==
"ERROR")
119 std::ostringstream
os;
123 Log& operator =(
const Log&);
133 static FILE* pStream = stderr;
139 if (!pStream)
return;
141 fprintf(pStream,
"%s", msg.c_str());
164 strftime(buffer,
sizeof(buffer),
"%Y-%m-%d %H:%M:%S", localtime_r(&t, &r));
166 gettimeofday(&tv, 0);
167 char result[100] = {0};
168 sprintf(result,
"%s.%06ld", buffer, (
long)tv.tv_usec / 1000);
177 #define SCXML4CPP_LOG(level) \
178 if (level > scxml4cpp::LOG_MAX_LEVEL) ; \
179 else if (level > scxml4cpp::Log<scxml4cpp::Output2FILE>::ReportingLevel() || !scxml4cpp::Output2FILE::Stream()) ; \
180 else scxml4cpp::Log<scxml4cpp::Output2FILE>().Get(level) << "scxml4cpp " << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ << " "
182 #define SCXML4CPP_LOG_TRACE() SCXML4CPP_LOG(scxml4cpp::LOG_LEVEL_TRACE)
183 #define SCXML4CPP_LOG_DEBUG() SCXML4CPP_LOG(scxml4cpp::LOG_LEVEL_DEBUG)
184 #define SCXML4CPP_LOG_DEBUG1() SCXML4CPP_LOG(scxml4cpp::LOG_LEVEL_DEBUG1)
185 #define SCXML4CPP_LOG_DEBUG2() SCXML4CPP_LOG(scxml4cpp::LOG_LEVEL_DEBUG2)
186 #define SCXML4CPP_LOG_DEBUG3() SCXML4CPP_LOG(scxml4cpp::LOG_LEVEL_DEBUG3)
187 #define SCXML4CPP_LOG_DEBUG4() SCXML4CPP_LOG(scxml4cpp::LOG_LEVEL_DEBUG4)
188 #define SCXML4CPP_LOG_INFO() SCXML4CPP_LOG(scxml4cpp::LOG_LEVEL_INFO)
189 #define SCXML4CPP_LOG_WARNING() SCXML4CPP_LOG(scxml4cpp::LOG_LEVEL_WARNING)
190 #define SCXML4CPP_LOG_ERROR() SCXML4CPP_LOG(scxml4cpp::LOG_LEVEL_ERROR)
const int LOG_LEVEL_WARNING
Definition: Log.h:27
void LogSetLevel(const std::string &levelName)
Definition: Log.h:149
std::ostringstream os
Definition: Log.h:119
static int FromString(const std::string &level)
Definition: Log.h:95
static std::string ToString(const int level)
Definition: Log.h:77
const int LOG_LEVEL_DEBUG2
Definition: Log.h:31
const int LOG_LEVEL_DEBUG1
Definition: Log.h:30
virtual ~Log()
Definition: Log.h:51
static int & ReportingLevel()
Definition: Log.h:69
optional string msg
Definition: topics.proto:7
const int LOG_LEVEL_DEBUG4
Definition: Log.h:33
static void Output(const std::string &msg)
Definition: Log.h:137
static FILE *& Stream()
Definition: Log.h:132
const int LOG_LEVEL_TRACE
Definition: Log.h:34
const int LOG_LEVEL_INFO
Definition: Log.h:28
const int LOG_LEVEL_DEBUG
Definition: Log.h:29
std::ostringstream & Get(const int level=LOG_LEVEL_INFO)
Definition: Log.h:60
std::string LogNowTime()
Definition: Log.h:158
const int LOG_LEVEL_ERROR
Definition: Log.h:26
Log()
Definition: Log.h:46
const int LOG_MAX_LEVEL
Definition: Log.h:35
const int LOG_LEVEL_DEBUG3
Definition: Log.h:32