nidas v1.2.3
|
A class for formatting and streaming a log message. More...
#include <Logger.h>
Public Member Functions | |
LogMessage (const std::string &s="") | |
Create a LogMessage, optionally set to an initial string. | |
LogMessage (const LogContextState *lp, const std::string &s="") | |
Associate this LogMessage with a LogContext. | |
LogMessage (const LogMessage &right) | |
LogMessage & | operator= (const LogMessage &right) |
LogMessage & | format (const char *fmt,...) |
std::string | getMessage () const |
operator std::string () const | |
template<typename T > | |
LogMessage & | operator<< (const T &t) |
Everything streamed to a LogMessage is passed on to the underlying ostringstream, including ostream manipulators. | |
~LogMessage () | |
If this message was associated with a LogContext, then send the completed message to it when this instance is destroyed, ie, when it goes out of scope. | |
std::streampos | length () |
Return the length of the current message buffer. | |
void | log () |
If this LogMessage is associated with a LogContext and if the current message is not empty, then log the current message with the LogContext. | |
Private Attributes | |
std::ostringstream | msg |
const LogContextState * | _log_context |
A class for formatting and streaming a log message.
Text can be appended to the message with a printf() format or streamed with the stream output operator<<. The implementation essentially wraps an ostringstream.
|
inline |
Create a LogMessage, optionally set to an initial string.
References msg.
|
inline |
Associate this LogMessage with a LogContext.
When the LogMessage is destroyed (eg, goes out of scope) or when the log() method is called, the current message (if any) is logged through the LogContext::log() method. The message optionally can be given an initial value.
This can be used to build up complicated logging messages which must be streamed incrementally, possibly dispersed throughout the code. Instantiate a LogContext and associate a LogMessage with it, then stream to the LogMessage if the context is active. The LogMessage can be reused to send multiple log messages, or to stream data and push the log message when it gets too long.
References msg.
|
inline |
References msg.
|
inline |
If this message was associated with a LogContext, then send the completed message to it when this instance is destroyed, ie, when it goes out of scope.
References log().
LogMessage & LogMessage::format | ( | const char * | fmt, |
... ) |
References buffer, fillError(), and msg.
Referenced by nidas::core::BadSampleFilter::invalidSampleHeader(), nidas::dynld::iss::TiltSensor::process(), and nidas::dynld::StatisticsCruncher::receive().
|
inline |
References msg.
|
inline |
|
inline |
If this LogMessage is associated with a LogContext and if the current message is not empty, then log the current message with the LogContext.
Clear the buffer and start a new message.
References _log_context, length(), and msg.
Referenced by nidas::dynld::StatisticsCruncher::attach(), nidas::util::endlog(), nidas::core::BadSampleFilter::invalidSampleHeader(), nidas::core::CharacterSensor::searchSampleScanners(), and ~LogMessage().
|
inline |
References msg.
|
inline |
References _log_context, and msg.
|
private |
Referenced by log(), and operator=().
|
private |
Referenced by format(), getMessage(), length(), log(), LogMessage(), LogMessage(), LogMessage(), operator std::string(), operator<<(), and operator=().