From: <sv...@ww...> - 2004-06-27 07:56:42
|
Author: mkrose Date: 2004-06-27 00:56:34 -0700 (Sun, 27 Jun 2004) New Revision: 1074 Modified: trunk/CSP/SimData/CHANGES.current trunk/CSP/SimData/Include/SimData/LogStream.h trunk/CSP/SimData/Include/SimData/ThreadLog.h Log: Add doxygen comments to ThreadLog.h Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1074 Modified: trunk/CSP/SimData/CHANGES.current =================================================================== --- trunk/CSP/SimData/CHANGES.current 2004-06-27 07:35:54 UTC (rev 1073) +++ trunk/CSP/SimData/CHANGES.current 2004-06-27 07:56:34 UTC (rev 1074) @@ -24,6 +24,8 @@ * Improved the traceback generation under linux. Tracebacks can be decoded with the tools/trace program. + * Add doxygen comments to ThreadLog.h + 2004-06-22: onsight * Added a ScopedUnlock (trivial reversal of ScopedLock) Modified: trunk/CSP/SimData/Include/SimData/LogStream.h =================================================================== --- trunk/CSP/SimData/Include/SimData/LogStream.h 2004-06-27 07:35:54 UTC (rev 1073) +++ trunk/CSP/SimData/Include/SimData/LogStream.h 2004-06-27 07:56:34 UTC (rev 1074) @@ -76,10 +76,12 @@ { public: - /** Constructor */ + /** Constructor + */ LogBuffer(); - /** Destructor */ + /** Destructor + */ ~LogBuffer(); /** Test if logging is enabled. Modified: trunk/CSP/SimData/Include/SimData/ThreadLog.h =================================================================== --- trunk/CSP/SimData/Include/SimData/ThreadLog.h 2004-06-27 07:35:54 UTC (rev 1073) +++ trunk/CSP/SimData/Include/SimData/ThreadLog.h 2004-06-27 07:56:34 UTC (rev 1074) @@ -40,11 +40,10 @@ NAMESPACE_SIMDATA -/** An output-only, category-based log stream. +/** A steam buffer class for thread-safe logging. * - * logbuf is an output-only streambuf with the ability to disable sets of - * messages at runtime. Only messages with priority >= logbuf::logPriority - * and debugClass == logbuf::logClass are output. + * StringBufs are used internally by ThreadLog to provide serialized + * access to a LogStream. */ class SIMDATA_EXPORT StringBuf: public NonCopyable, public std::streambuf { @@ -60,22 +59,31 @@ protected: + // accessed directly by ThreadLog LogStream &m_log; typedef ScopedLock<LogStream> ScopedLogLock; + /** Default constructor, connects to the global simdata log. + */ StringBuf(): m_category(LOG_ALL), m_priority(LOG_INFO), m_file(0), m_line(0), m_log(::simdata::log()) { init(); } + /** Constructor, connects to the specified LogStream + */ StringBuf(LogStream &base): m_category(LOG_ALL), m_priority(LOG_INFO), m_log(base) { init(); } + /** Overflow (cache characters internally) + */ virtual int overflow(int c) { m_buffer.push_back(static_cast<char>(c)); return 1; } + /** Sync/flush the cached log entry to the underlying LogStream + */ virtual int sync() { ScopedLogLock lock(m_log); std::ostream &entry = m_log.entry(m_priority, m_category, m_file, m_line); @@ -85,6 +93,8 @@ return 1; } + /** Cache the log entry parameters. + */ inline void setPrefix(int priority, int category, const char *file, int line) { m_priority = priority; m_category = category; @@ -94,56 +104,95 @@ }; + +/** A thread-safe logging class that provides serialized access to an + * underlying LogStream instance. The public interface is the same as + * LogStream, and the logging macro as defined to use thread-specific + * ThreadLog instances instead of the global LogStream whenever threading + * is enabled. + */ class SIMDATA_EXPORT ThreadLog: private StringBuf, protected std::ostream { public: + /** Default constructor, connects to the global simdata log. + */ ThreadLog(): std::ostream(this) {} + /** Constructor, connects to the specified LogStream + */ ThreadLog(LogStream &base): StringBuf(base), std::ostream(this) {} + /** Close the underlying (shared) LogStream. + */ void _close() { ScopedLogLock lock(m_log); m_log._close(); } + /** Set the output stream used by the underlying (shared) LogStream. + */ void setOutput(std::ostream& out_) { ScopedLogLock lock(m_log); m_log.setOutput(out_); } + /** Set the output file used by the underlying (shared) LogStream. + */ void setOutput(std::string const &filename) { ScopedLogLock lock(m_log); m_log.setOutput(filename); } + /** Set the logging priority threshold of the underlying (shared) LogStream. + */ void setLogPriority(int p) { ScopedLogLock lock(m_log); m_log.setLogPriority(p); } + /** Set the logging category mask of the underlying (shared) LogStream. + */ void setLogCategory(int c) { ScopedLogLock lock(m_log); m_log.setLogCategory(c); } + /** Enable or disable point logging (source file and line number) by the + * underlying (shared) LogStream. + */ void setPointLogging(bool enabled) { ScopedLogLock lock(m_log); m_log.setPointLogging(enabled); } + /** Get the point logging state of the underlying (shared) LogStream. + */ bool getPointLogging() const { return m_log.getPointLogging(); } + /** Enable or disable time stamping of log entries written to the + * underlying (shared) LogStream. + */ void setTimeLogging(bool enabled) { ScopedLogLock lock(m_log); m_log.setTimeLogging(enabled); } + /** Get the time logging state of the underlying (shared) LogStream. + */ bool getTimeLogging() const { return m_log.getTimeLogging(); } + /** Method for logging a message to the underlying (shared) LogStream. + * + * @param priority priority of this message. + * @param category category of this message (default ALL). + * @param file source file that generated this message; typically __FILE__. + * @param line line number of the code that generated this message (typically __LINE__). + * @return an output stream to receive the message contents. + */ std::ostream & entry(int priority, int category=LOG_ALL, const char *file=0, int line=0) { setPrefix(priority, category, file, line); return *this; |