Go to the documentation of this file.
43 #ifndef LOGSTREAMINCLUDE
44 #define LOGSTREAMINCLUDE
50 #include "gnsstk_export.h"
60 #ifndef FILELOG_MAX_LEVEL
61 #define FILELOG_MAX_LEVEL DEBUG7
66 template <
class T>
class Log
87 std::ostringstream
os;
89 #ifdef WIN32 // see kludge note below
90 GNSSTK_EXPORT
static LogLevel reportingLevel;
91 GNSSTK_EXPORT
static bool dumpTimeTags;
92 GNSSTK_EXPORT
static bool dumpLevels;
105 os << ToString(level) <<
": ";
107 if(level >
DEBUG) os << std::string(2*(level-
DEBUG),
' ');
120 #ifndef WIN32 // see kludge note below
121 static bool dumpLevels =
false;
128 #ifndef WIN32 // see kludge note below
129 static bool dumpTimeTags =
false;
136 #ifndef WIN32 // see kludge note below
139 return reportingLevel;
145 static const char*
const buffer[] = {
"ERROR",
"WARNING",
"INFO",
"VERBOSE",
146 "DEBUG",
"DEBUG1",
"DEBUG2",
"DEBUG3",
"DEBUG4",
"DEBUG5",
"DEBUG6",
"DEBUG7" };
147 return buffer[level];
153 if(level ==
"DEBUG7")
return DEBUG7;
154 if(level ==
"DEBUG6")
return DEBUG6;
155 if(level ==
"DEBUG5")
return DEBUG5;
156 if(level ==
"DEBUG4")
return DEBUG4;
157 if(level ==
"DEBUG3")
return DEBUG3;
158 if(level ==
"DEBUG2")
return DEBUG2;
159 if(level ==
"DEBUG1")
return DEBUG1;
160 if(level ==
"DEBUG")
return DEBUG;
161 if(level ==
"VERBOSE")
return VERBOSE;
162 if(level ==
"INFO")
return INFO;
163 if(level ==
"WARNING")
return WARNING;
164 if(level ==
"ERROR")
return ERROR;
166 <<
"Unknown logging level '" << level <<
"'. Using INFO level instead.";
173 #include <sys/timeb.h>
179 double dt=double(sec)+t.millitm/1000.;
180 sec -= long(dt/86400)*86400;
181 dt = double(sec)+t.millitm/1000.;
182 char result[100] = {0};
189 std::sprintf(result,
"%02d:%02d:%02d.%03d",h,m,s,
int(dt*1000.));
195 #include <sys/time.h>
202 strftime(buffer,
sizeof(buffer),
"%X", localtime_r(&t, &r));
204 gettimeofday(&tv, 0);
205 char result[100] = {0};
206 std::sprintf(result,
"%s.%03ld", buffer, (
long)tv.tv_usec / 1000);
282 static std::ostream*&
Stream();
285 static void Output(
const std::string& msg);
290 static std::ostream *pStream = &(std::cout);
296 std::ostream *pStream =
Stream();
298 *pStream << msg << std::flush;
316 if(level <= FILELOG_MAX_LEVEL && \
317 level <= ConfigureLOG::ReportingLevel() && \
318 ConfigureLOGstream::Stream()) ConfigureLOG().Put(level)
321 #define pLOGstrm ConfigureLOGstream::Stream()
322 #define LOGstrm *(ConfigureLOGstream::Stream())
323 #define LOGlevel ConfigureLOG::ReportingLevel()
333 #endif //LOGSTREAMINCLUDE --- end of the include file. Test code follows in comments.
Log & operator=(const Log &)
do not implement
std::ostringstream os
string stream to which output is written; destructor will dump to log stream.
static std::string ToString(LogLevel level)
convert a level to a string corresponding to the LogLevel enum
static LogLevel & ReportingLevel()
get/set the highest level that is actually output to log stream
std::ostringstream & Put(LogLevel level=INFO)
write out to log stream at level, default is INFO
std::string NowTime(void)
generate a timetag as string
static LogLevel FromString(const std::string &level)
convert from a string (= names in the LogLevel enum) to a LogLevel
static bool & ReportLevels()
get/set; if true, output level on each line, after the time tag
static bool & ReportTimeTags()
get/set; if true, output time tag on each line, first
gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:39