From: <sv...@ww...> - 2005-11-13 22:41:46
|
Author: mkrose Date: 2005-11-13 14:41:39 -0800 (Sun, 13 Nov 2005) New Revision: 1673 Modified: trunk/CSP/SimData/Include/SimData/LogStream.h trunk/CSP/SimData/Source/ExceptionBase.cpp trunk/CSP/SimData/Source/LogStream.cpp trunk/CSP/SimData/Source/Trace.cpp Log: More logging fixes. Change priority and formatting constants to avoid collisions with macro names under windows. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1673 Modified: trunk/CSP/SimData/Include/SimData/LogStream.h =================================================================== --- trunk/CSP/SimData/Include/SimData/LogStream.h 2005-11-13 20:41:44 UTC (rev 1672) +++ trunk/CSP/SimData/Include/SimData/LogStream.h 2005-11-13 22:41:39 UTC (rev 1673) @@ -50,8 +50,8 @@ class SIMDATA_EXPORT LogStream { public: /// Flags controlling log metadata. - enum { TERSE=0, PRIORITY=1, DATESTAMP=2, TIMESTAMP=4, LINESTAMP=8, FULLPATH=16, THREAD=32, VERBOSE=~0 }; - enum { DEBUG=0, INFO=1, WARNING=2, ERROR=3, FATAL=4 }; + enum { cTerse=0, cPriority=1, cDatestamp=2, cTimestamp=4, cLinestamp=8, cFullPath=16, cThread=32, cVerbose=~0 }; + enum { cDebug=0, cInfo=1, cWarning=2, cError=3, cFatal=4 }; /** Create a new log stream that defaults to stderr. */ @@ -183,7 +183,7 @@ * * @param stream the logstream to write to. * @param priority priority of this message. - * If non-negative and the logstream's flags include PRIORITY, this + * If non-negative and the logstream's flags include cPriority, this * priority will be recorded in the message. Note that this is only * an advisory value; it is up to the creator of the LogEntry to * filter messages based on priority. @@ -196,7 +196,7 @@ * * @param stream the logstream to write to. * @param priority priority of this message. - * If non-negative and the logstream's flags includes PRIORITY, this + * If non-negative and the logstream's flags includes cPriority, this * priority will be recorded in the message. Note that this is only * an advisory value; it is up to the creator of the LogEntry to * filter messages based on priority. @@ -209,14 +209,14 @@ /** Write the buffered log entry to the logstream. Locks the stream during the * write operation if running in a multithreaded environment. If the priority - * is FATAL, records a stack trace and aborts the program. + * is cFatal, records a stack trace and aborts the program. */ ~LogEntry() { m_stream.lock(); m_stream.getStream() << m_buffer.get() << "\n"; - if (m_priority >= LogStream::WARNING) m_stream.flush(); + if (m_priority >= LogStream::cWarning) m_stream.flush(); m_stream.unlock(); - if (m_priority == LogStream::FATAL) die(); + if (m_priority == LogStream::cFatal) die(); } /** Stream operator for recording messages in the log entry. Modified: trunk/CSP/SimData/Source/ExceptionBase.cpp =================================================================== --- trunk/CSP/SimData/Source/ExceptionBase.cpp 2005-11-13 20:41:44 UTC (rev 1672) +++ trunk/CSP/SimData/Source/ExceptionBase.cpp 2005-11-13 22:41:39 UTC (rev 1673) @@ -102,7 +102,7 @@ void ExceptionBase::logAndClear(int category) const { if (SIMDATA_NOTEWORTHY(LOG_ERROR, category)) { - LogStream::LogEntry(SIMDATA_LOG_, LogStream::ERROR) << *this; + LogStream::LogEntry(SIMDATA_LOG_, LogStream::cError) << *this; } } Modified: trunk/CSP/SimData/Source/LogStream.cpp =================================================================== --- trunk/CSP/SimData/Source/LogStream.cpp 2005-11-13 20:41:44 UTC (rev 1672) +++ trunk/CSP/SimData/Source/LogStream.cpp 2005-11-13 22:41:39 UTC (rev 1673) @@ -63,7 +63,7 @@ if (env_priority && *env_priority) { int priority = atoi(env_priority); if (priority < 0) priority = 0; - if (priority > FATAL) priority = FATAL; + if (priority > cFatal) priority = cFatal; setPriority(priority); } } @@ -78,18 +78,18 @@ void LogStream::LogEntry::prefix(const char *filename, int linenum) { const int flags = m_stream.getFlags(); - if (flags & LogStream::PRIORITY) { + if (flags & LogStream::cPriority) { m_buffer << ((m_priority >= 0 && m_priority <= 4) ? "DIWEF"[m_priority] : '?') << " "; } - if (flags & (LogStream::TIMESTAMP|LogStream::DATESTAMP)) { + if (flags & (LogStream::cTimestamp|LogStream::cDatestamp)) { const time_t now = time(0); struct tm gmt; gmtime_r(&now, &gmt); char time_stamp[32]; - switch (flags & (LogStream::TIMESTAMP|LogStream::DATESTAMP)) { - case LogStream::TIMESTAMP: + switch (flags & (LogStream::cTimestamp|LogStream::cDatestamp)) { + case LogStream::cTimestamp: strftime(time_stamp, 32, "%H%M%S", &gmt); break; - case LogStream::DATESTAMP: + case LogStream::cDatestamp: strftime(time_stamp, 32, "%Y%m%d", &gmt); break; default: strftime(time_stamp, 32, "%Y%m%d %H%M%S", &gmt); @@ -97,7 +97,7 @@ m_buffer << time_stamp << ' '; } #ifndef SIMDATA_NOTHREADS - if (flags & LogStream::THREAD) { + if (flags & LogStream::cThread) { pthread_t thread_id = thread::id(); if (!pthread_equal(thread_id, m_stream.initialThread())) { // compress the low 32 or 36 bits of thread id into 6 characters. note that this is *not* @@ -113,9 +113,9 @@ } } #endif - if (filename && (flags & LogStream::LINESTAMP)) { + if (filename && (flags & LogStream::cLinestamp)) { const char *basename = filename; - if ((flags & LogStream::FULLPATH) == 0) { + if ((flags & LogStream::cFullPath) == 0) { for (const char *scanner = filename; *scanner; ++scanner) { if (*scanner == ospath::DIR_SEPARATOR) basename = scanner + 1; } @@ -149,8 +149,8 @@ } LogStream::LogStream(): - m_flags(PRIORITY|TIMESTAMP|LINESTAMP|THREAD), - m_priority(INFO), + m_flags(cPriority|cTimestamp|cLinestamp|cThread), + m_priority(cInfo), m_categories(~0), m_stream(&std::cerr), m_fstream(0) { @@ -158,8 +158,8 @@ } LogStream::LogStream(std::ostream& stream): - m_flags(PRIORITY|TIMESTAMP|LINESTAMP|THREAD), - m_priority(INFO), + m_flags(cPriority|cTimestamp|cLinestamp|cThread), + m_priority(cInfo), m_categories(~0), m_stream(&stream), m_fstream(0) { Modified: trunk/CSP/SimData/Source/Trace.cpp =================================================================== --- trunk/CSP/SimData/Source/Trace.cpp 2005-11-13 20:41:44 UTC (rev 1672) +++ trunk/CSP/SimData/Source/Trace.cpp 2005-11-13 22:41:39 UTC (rev 1673) @@ -182,7 +182,7 @@ _trace.acquire(/*skip=*/3); LogStream *logstream = log(); // don't log at FATAL priority since that allocates another stack trace. - LogStream::LogEntry(*logstream, LogStream::ERROR) << "FATAL ERROR: segmentation fault"; + LogStream::LogEntry(*logstream, LogStream::cError) << "FATAL ERROR: segmentation fault"; logstream->trace(&_trace); _abort = false; // prevent the abort handler from also logging a trace abort(); @@ -194,7 +194,7 @@ if (_reserve) free(_reserve); _reserve = 0; // free some memory! _trace.acquire(/*skip=*/3); LogStream *logstream = log(); - LogStream::LogEntry(*logstream, LogStream::FATAL) << "ABORT"; + LogStream::LogEntry(*logstream, LogStream::cFatal) << "ABORT"; } } @@ -202,7 +202,7 @@ _trace.acquire(/*skip=*/3); LogStream *logstream = log(); _abort = false; - LogStream::LogEntry(*logstream, LogStream::FATAL) << "TERMINATED"; + LogStream::LogEntry(*logstream, LogStream::cFatal) << "TERMINATED"; } LogStream *AutoTrace::log() { |