List of all members | Classes | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
utl::MessageLogger Class Reference

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...
 

Detailed Description

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.

Author
Rodolfo Federico Gamarra
Date
09 Sep 2009

Definition at line 38 of file MessageLogger.h.

Constructor & Destructor Documentation

utl::MessageLogger::MessageLogger ( std::ostream &  os,
unsigned int  l 
)

Construct a logger to handle the messages.

Parameters
osOutput stream, not used if not good. A reference is kept.
lDesired level.
See Also
std::ios_base::goodbit
std::ostream::good

Definition at line 53 of file MessageLogger.cc.

Member Function Documentation

unsigned int utl::MessageLogger::GetFlushPeriod ( ) const
inline

Return the current period.

See Also
fFlushPeriod

Definition at line 182 of file MessageLogger.h.

References fFlushPeriod.

unsigned int utl::MessageLogger::GetLevel ( ) const
inline

Return the current level set.

Definition at line 164 of file MessageLogger.h.

References fLevel.

unsigned int utl::MessageLogger::GetNPrecDigits ( ) const
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().

template<typename T >
void utl::MessageLogger::Log ( const T &  message,
unsigned int  l 
)
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().

template<typename T >
Message utl::MessageLogger::operator() ( const T &  message,
unsigned int  level,
bool  trailEOL 
)
inline

Start of message logging.

Parameters
messageInitial message.
levelLevel of the message to be started.
trailEOLIf 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.

std::ostream& utl::MessageLogger::ResolveStream ( )
inlineprivate
void utl::MessageLogger::SetFlushPeriod ( unsigned int  p)
inline

Set a new period.

See Also
fFlushPeriod

Definition at line 188 of file MessageLogger.h.

References fFlushPeriod, and G4StationSimulatorOG::p.

Referenced by utl::MessageLoggerConfig::ApplyConfiguration().

void utl::MessageLogger::SetLevel ( unsigned int  l)
inline

Set a new level.

Definition at line 168 of file MessageLogger.h.

References fLevel.

Referenced by utl::MessageLoggerConfig::ApplyConfiguration().

void utl::MessageLogger::SetNPrecDigits ( unsigned int  n)
inline

Set a new number of digits.

Definition at line 176 of file MessageLogger.h.

References fNPrecDigits.

Referenced by utl::MessageLoggerConfig::ApplyConfiguration().

Member Data Documentation

template<class S >
void utl::MessageLogger::const
Initial value:
{
stream << std::setprecision(fNPrecDigits) << std::fixed

Apply configuration to the given stream via manipulators.

Definition at line 196 of file MessageLogger.h.

unsigned int utl::MessageLogger::fFlushCounter
private

Current flush count.

Definition at line 218 of file MessageLogger.h.

Referenced by Log().

unsigned int utl::MessageLogger::fFlushPeriod
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().

unsigned int utl::MessageLogger::fLevel
private

Threshold level for message output.

Definition at line 214 of file MessageLogger.h.

Referenced by GetLevel(), Log(), and SetLevel().

unsigned int utl::MessageLogger::fNPrecDigits
private

Definition at line 216 of file MessageLogger.h.

Referenced by GetNPrecDigits(), and SetNPrecDigits().

std::ostream& utl::MessageLogger::fStream
private

Output stream.

Definition at line 212 of file MessageLogger.h.

Referenced by ResolveStream().


The documentation for this class was generated from the following files:

, generated on Tue Sep 26 2023.