Handle diagnosis messages output. More...
#include <MessageLogger.h>
Classes | |
class | Message |
Message object. More... | |
Public Member Functions | |
unsigned int | GetFlushPeriod () const |
Return the current period. More... | |
unsigned int | GetLevel () const |
Return the current level set. More... | |
unsigned int | GetNPrecDigits () const |
Return the number of digits for floating-point numbers. More... | |
template<typename T > | |
void | Log (const T &message, unsigned int l) |
Actual logging function against the given stream. More... | |
MessageLogger (std::ostream &os, unsigned int l) | |
Construct a logger to handle the messages. More... | |
template<typename T > | |
Message | operator() (const T &message, unsigned int level, bool trailEOL) |
Start of message logging. More... | |
void | SetFlushPeriod (unsigned int p) |
Set a new period. More... | |
void | SetLevel (unsigned int l) |
Set a new level. More... | |
void | SetNPrecDigits (unsigned int n) |
Set a new number of digits. More... | |
Public Attributes | |
template<class S > | |
void | const |
Apply configuration to the given stream via manipulators. More... | |
Private Member Functions | |
std::ostream & | ResolveStream () |
Private Attributes | |
unsigned int | fFlushCounter |
Current flush count. More... | |
unsigned int | fFlushPeriod |
Flush the stream every this number of times of calls to Log (zero means no flush at all). More... | |
unsigned int | fLevel |
Threshold level for message output. More... | |
unsigned int | fNPrecDigits |
std::ostream & | fStream |
Output stream. More... | |
Handle diagnosis messages output.
Helper class to handle the output of messages, mainly to be used in the modules. Originally, something like this was crafted as a particular concern of a given module: after needing the same in another one, it seemed reasonable to factor it out in an util class.
Taking a quick look in what's currently done in the modules, std::cout is mainly primarly used, with the level conditioning put in place. The use of this wrapping class seems cleaner: allow another kind of ostream, wrap the conditions and the chaining allows appending without needing, say, a stringstream in client code: a given message can be handled in a single line.
Definition at line 38 of file MessageLogger.h.
utl::MessageLogger::MessageLogger | ( | std::ostream & | os, |
unsigned int | l | ||
) |
Construct a logger to handle the messages.
os | Output stream, not used if not good. A reference is kept. |
l | Desired level. |
Definition at line 53 of file MessageLogger.cc.
|
inline |
Return the current period.
Definition at line 182 of file MessageLogger.h.
References fFlushPeriod.
|
inline |
|
inline |
Return the number of digits for floating-point numbers.
Definition at line 172 of file MessageLogger.h.
References fNPrecDigits.
Referenced by utl::MessageLogger::Message::Message().
|
inline |
Actual logging function against the given stream.
Definition at line 143 of file MessageLogger.h.
References fFlushCounter, fFlushPeriod, fLevel, and ResolveStream().
Referenced by utl::MessageLogger::Message::Message(), utl::MessageLogger::Message::operator()(), and utl::MessageLogger::Message::~Message().
|
inline |
Start of message logging.
message | Initial message. |
level | Level of the message to be started. |
trailEOL | If a trailing eol is meant to be put at last. |
This function outputs an initial message and constructs the intermediate object.
Definition at line 136 of file MessageLogger.h.
|
inlineprivate |
Definition at line 205 of file MessageLogger.h.
References fStream.
Referenced by Log(), utl::MessageLogger::Message::Message(), and utl::MessageLogger::Message::~Message().
|
inline |
Set a new period.
Definition at line 188 of file MessageLogger.h.
References fFlushPeriod, and G4StationSimulatorOG::p.
Referenced by utl::MessageLoggerConfig::ApplyConfiguration().
|
inline |
Set a new level.
Definition at line 168 of file MessageLogger.h.
References fLevel.
Referenced by utl::MessageLoggerConfig::ApplyConfiguration().
|
inline |
Set a new number of digits.
Definition at line 176 of file MessageLogger.h.
References fNPrecDigits.
Referenced by utl::MessageLoggerConfig::ApplyConfiguration().
void utl::MessageLogger::const |
Apply configuration to the given stream via manipulators.
Definition at line 196 of file MessageLogger.h.
|
private |
|
private |
Flush the stream every this number of times of calls to Log (zero means no flush at all).
Definition at line 220 of file MessageLogger.h.
Referenced by GetFlushPeriod(), Log(), and SetFlushPeriod().
|
private |
Threshold level for message output.
Definition at line 214 of file MessageLogger.h.
Referenced by GetLevel(), Log(), and SetLevel().
|
private |
Definition at line 216 of file MessageLogger.h.
Referenced by GetNPrecDigits(), and SetNPrecDigits().
|
private |