24 std::ostringstream
os;
39 os <<
" " << ToString(level) <<
": ";
55 return reportingLevel;
61 static const char*
const buffer[] = {
"ERROR",
"WARNING",
"INFO",
"DEBUG",
"DEBUG1",
"DEBUG2",
"DEBUG3",
"DEBUG4"};
68 if (level ==
"DEBUG4")
70 if (level ==
"DEBUG3")
72 if (level ==
"DEBUG2")
74 if (level ==
"DEBUG1")
80 if (level ==
"WARNING")
84 Log<T>().Get(
logWARNING) <<
"Unknown logging level '" << level <<
"'. Using INFO level as default.";
92 static void Output(
const std::string& msg);
97 static FILE* pStream = stderr;
106 fprintf(pStream,
"%s", msg.c_str());
110 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
111 # if defined (BUILDING_FILELOG_DLL)
112 # define FILELOG_DECLSPEC __declspec (dllexport)
113 # elif defined (USING_FILELOG_DLL)
114 # define FILELOG_DECLSPEC __declspec (dllimport)
116 # define FILELOG_DECLSPEC
117 # endif // BUILDING_DBSIMPLE_DLL
119 # define FILELOG_DECLSPEC
125 #ifndef FILELOG_MAX_LEVEL
126 #define FILELOG_MAX_LEVEL logDEBUG4
129 #define FILE_LOG(level) \
130 if (level > FILELOG_MAX_LEVEL) ;\
131 else if (level > FILELog::ReportingLevel() || !Output2FILE::Stream()) ; \
132 else FILELog().Get(level)
134 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
140 const int MAX_LEN = 200;
141 char buffer[MAX_LEN];
142 if (GetTimeFormatA(LOCALE_USER_DEFAULT, 0, 0,
143 "HH':'mm':'ss", buffer, MAX_LEN) == 0)
144 return "Error in NowTime()";
146 char result[100] = {0};
147 static DWORD first = GetTickCount();
148 std::sprintf(result,
"%s.%03ld", buffer, (
long)(GetTickCount() - first) % 1000);
154 #include <sys/time.h>
162 strftime(buffer,
sizeof(buffer),
"%X", localtime_r(&t, &r));
164 gettimeofday(&tv, 0);
165 char result[100] = {0};
166 sprintf(result,
"%s.%03ld", buffer, (
long)tv.tv_usec / 1000);
static FILE *& Stream()
Definition: log.h:95
static void Output(const std::string &msg)
Definition: log.h:101
std::string NowTime()
Definition: log.h:156
Log()
Definition: log.h:31
std::ostringstream & Get(TLogLevel level=logINFO)
Definition: log.h:36
virtual ~Log()
Definition: log.h:45
static TLogLevel FromString(const std::string &level)
Definition: log.h:66
#define FILELOG_DECLSPEC
Definition: log.h:119
static TLogLevel & ReportingLevel()
Definition: log.h:52
static std::string ToString(TLogLevel level)
Definition: log.h:59
std::ostringstream os
Definition: log.h:24
Log & operator=(const Log &)
TLogLevel
Definition: log.h:10