SLIC  6.1.1
Simulation for the Linear Collider (SLIC) - Geant4 simulation application
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
LogStream Class Reference

A class for streaming messages to a log. More...

#include <LogStream.hh>

Public Member Functions

LogStream & always ()
 
void always (const std::string &mesg)
 
int bad () const
 
void clear (std::ios_base::iostate _i=std::ios_base::failbit)
 
LogStream & debug ()
 
void debug (const std::string &mesg)
 
int eof () const
 
LogStream & error ()
 
void error (const std::string &mesg)
 
LogStream & fatal ()
 
void fatal (const std::string &mesg)
 
char fill () const
 
char fill (char v)
 
long flags () const
 
long flags (std::ios_base::fmtflags v)
 
LOG::ELevel getCurrentLevel () const
 
const std::string & getName () const
 
LOG::ELevel getOutputLevel () const
 
ostream & getOutputStream () const
 
int good () const
 
bool isActive () const
 
void log (const std::string &mesg)
 
void log (const std::string &message, const LOG::ELevel &level)
 
LogStream & okay ()
 
void okay (const std::string &mesg)
 
LogStream & operator<< (const LOG::ELevel &level)
 
LogStream & operator<< (const LOG::EManip &x)
 
template<typename T >
LogStream & operator<< (const std::vector< T > &v)
 
template<typename T >
LogStream & operator<< (const T &arg)
 
LogStream & operator<< (ios &(*manip)(std::ios &))
 
LogStream & operator<< (std::ios_base &(*manip)(std::ios_base &))
 
int precision () const
 
int precision (int v)
 
int rdstate () const
 
void setCurrentLevel (LOG::ELevel level)
 
long setf (std::ios_base::fmtflags _f, std::ios_base::fmtflags _m)
 
long setf (std::ios_base::fmtflags v)
 
void setOutputFile (const std::string &file)
 
void setOutputLevel (const LOG::ELevel &outputLevel)
 
void unsetf (std::ios_base::fmtflags _l)
 
LogStream & verbose ()
 
void verbose (const std::string &mesg)
 
LogStream & warning ()
 
void warning (const std::string &mesg)
 
int width () const
 
int width (int v)
 

Protected Member Functions

 LogStream ()
 
 LogStream (std::string name, LOG::ELevel level, ostream *os=&std::cout)
 
virtual ~LogStream ()
 

Private Member Functions

void setActive (bool active)
 

Private Attributes

bool m_active
 
LOG::ELevel m_currentMessageLevel
 
std::ofstream * m_fos
 
std::string m_name
 
ostream * m_os
 
LOG::ELevel m_outputLevel
 

Friends

class LogManager
 

Detailed Description

A class for streaming messages to a log.

Note
LogStream provides methods for logging messages at a certain level. The LogStream has a default level, and if a message's log level is greater than the current log level, it is discarded.
The stream operators are overloaded so that the LogStream can be used similarly to std::cout.
The manipulator LOG::done should be used to terminate a log message.
Some of the code, particularly the handling of ios manipulators, is based on Gaudi's MsgStream class.
For more information on the STL IO library see this reference page.

Definition at line 71 of file LogStream.hh.

Constructor & Destructor Documentation

◆ LogStream() [1/2]

LogStream ( std::string  name,
LOG::ELevel  level,
ostream *  os = &std::cout 
)
inlineprotected

Class constructor.

Parameters
[in]nameThe name of the LogStream.
[in]levelThe level of the logger.
[in]osThe output stream for printing message.

Definition at line 81 of file LogStream.hh.

◆ LogStream() [2/2]

LogStream ( )
inlineprotected

Class constructor providing default arguments.

Definition at line 89 of file LogStream.hh.

◆ ~LogStream()

virtual ~LogStream ( )
inlineprotectedvirtual

Class destructor.

Definition at line 97 of file LogStream.hh.

Member Function Documentation

◆ always() [1/2]

LogStream& always ( )
inline

Set the current level to always.

Returns
The LogStream.

Definition at line 278 of file LogStream.hh.

References LOG::always.

Referenced by PhysicsListManager::printAvailablePhysicsLists().

◆ always() [2/2]

void always ( const std::string &  mesg)
inline

Log a message at always level.

Parameters
[in]mesgThe message.

Definition at line 351 of file LogStream.hh.

References LOG::always, and LogStream::log().

◆ bad()

int bad ( ) const
inline

Return non-zero if error bits are set; otherwise return zero.

Returns
The bad state.

Definition at line 568 of file LogStream.hh.

References LogStream::getOutputStream(), and LogStream::isActive().

◆ clear()

void clear ( std::ios_base::iostate  _i = std::ios_base::failbit)
inline

Set a new value for the internal error state flags.

Parameters
[in]_iThe new error state flag value.

Definition at line 596 of file LogStream.hh.

References LogStream::getOutputStream(), and LogStream::isActive().

◆ debug() [1/2]

LogStream& debug ( )
inline

Set the current level to debug.

Returns
The LogStream.

Definition at line 230 of file LogStream.hh.

References LOG::debug.

◆ debug() [2/2]

void debug ( const std::string &  mesg)
inline

Log a message at debug level.

Parameters
[in]mesgThe message.

Definition at line 303 of file LogStream.hh.

References LOG::debug, and LogStream::log().

◆ eof()

int eof ( ) const
inline

Return zero if EOF has not been reached; otherwise return non-zero.

Returns
The EOF state.

Definition at line 560 of file LogStream.hh.

References LogStream::getOutputStream(), and LogStream::isActive().

◆ error() [1/2]

LogStream& error ( )
inline

Set the current level to error.

Returns
The LogStream.

Definition at line 262 of file LogStream.hh.

References LOG::error.

Referenced by LcioHitsCollectionBuilder::addParticleContributions(), LcioHitsCollectionBuilder::createHit(), and EventSourceManager::setupEventSource().

◆ error() [2/2]

void error ( const std::string &  mesg)
inline

Log a message at error level.

Parameters
[in]mesgThe message.

Definition at line 335 of file LogStream.hh.

References LOG::error, and LogStream::log().

◆ fatal() [1/2]

LogStream& fatal ( )
inline

Set the current level to fatal.

Returns
The LogStream.

Definition at line 270 of file LogStream.hh.

References LOG::fatal.

◆ fatal() [2/2]

void fatal ( const std::string &  mesg)
inline

Log a message at fatal level.

Parameters
[in]mesgThe message.

Definition at line 343 of file LogStream.hh.

References LOG::fatal, and LogStream::log().

◆ fill() [1/2]

char fill ( ) const
inline

Get the fill char.

Returns
The fill char.

Definition at line 510 of file LogStream.hh.

References LogStream::getOutputStream(), and LogStream::isActive().

◆ fill() [2/2]

char fill ( char  v)
inline

Set the fill char.

Parameters

Definition at line 519 of file LogStream.hh.

References LogStream::getOutputStream(), and LogStream::isActive().

◆ flags() [1/2]

long flags ( ) const
inline

Get the current set of flags.

Returns
The current set of ios formatting flags.

Definition at line 484 of file LogStream.hh.

References LogStream::getOutputStream(), and LogStream::isActive().

◆ flags() [2/2]

long flags ( std::ios_base::fmtflags  v)
inline

Set the formatting flags.

Parameters
[in]vThe formatting flags.
Returns
The current set of formatting flags.

Definition at line 493 of file LogStream.hh.

References LogStream::getOutputStream(), and LogStream::isActive().

◆ getCurrentLevel()

LOG::ELevel getCurrentLevel ( ) const
inline

Get the current log level for messages.

Returns
The current log level.

Definition at line 151 of file LogStream.hh.

References LogStream::m_currentMessageLevel.

Referenced by LogStream::operator<<().

◆ getName()

const std::string& getName ( ) const
inline

Get the name of the LogStream.

Returns
The name of the LogStream.

Definition at line 111 of file LogStream.hh.

References LogStream::m_name.

Referenced by LogMessenger::defineCommands(), and LogStream::operator<<().

◆ getOutputLevel()

LOG::ELevel getOutputLevel ( ) const
inline

Get the output level which determines which messages will be shown.

Returns
The output level.

Definition at line 127 of file LogStream.hh.

References LogStream::m_outputLevel.

Referenced by LogStream::log(), and LogStream::operator<<().

◆ getOutputStream()

ostream& getOutputStream ( ) const
inline

◆ good()

int good ( ) const
inline

Return 0 if no error bits are set.

Returns
The good state.

Definition at line 552 of file LogStream.hh.

References LogStream::getOutputStream(), and LogStream::isActive().

◆ isActive()

bool isActive ( ) const
inline

◆ log() [1/2]

void log ( const std::string &  mesg)
inline

Log a message at the current level (NOT output level).

Parameters
[in]mesgThe message.

Definition at line 295 of file LogStream.hh.

References LogStream::getOutputLevel(), and LogStream::log().

◆ log() [2/2]

void log ( const std::string &  message,
const LOG::ELevel &  level 
)
inline

Log a message at a certain level.

Parameters
[in]mesgThe message contents.
[in]levelThe log level.

Definition at line 287 of file LogStream.hh.

References LOG::done, and LOG::level.

Referenced by LogStream::always(), LogStream::debug(), LogStream::error(), LogStream::fatal(), LogStream::log(), LogStream::okay(), LogStream::verbose(), and LogStream::warning().

◆ okay() [1/2]

LogStream& okay ( )
inline

◆ okay() [2/2]

void okay ( const std::string &  mesg)
inline

Log a message at okay level.

Parameters
[in]mesgThe message.

Definition at line 319 of file LogStream.hh.

References LogStream::log(), and LOG::okay.

◆ operator<<() [1/6]

LogStream& operator<< ( const LOG::ELevel &  level)
inline

Set the log level via streamer. Subsequent messages will be placed onto the LogStream if the level is less than or equal to the current output level. Otherwise they will be discarded.

Parameters
[in]levelThe log level.
Returns
The current LogStream.

Definition at line 170 of file LogStream.hh.

References LogStream::getCurrentLevel(), LogStream::getOutputLevel(), LOG::level, LogStream::setActive(), and LogStream::setCurrentLevel().

◆ operator<<() [2/6]

LogStream& operator<< ( const LOG::EManip &  x)
inline

Handle ios manipulators for the LogStream.

Parameters
[in]xThe ios manipulator.
Returns
The LogStream.

Definition at line 189 of file LogStream.hh.

References LOG::done, LOG::endl, TimeUtil::getAscTime(), LogStream::getName(), LogStream::getOutputStream(), LOG::head, LogStream::isActive(), LOG::level, levelNames, LogStream::m_currentMessageLevel, LOG::name, LOG::sep, and LOG::time.

◆ operator<<() [3/6]

LogStream& operator<< ( const std::vector< T > &  v)
inline

Specialization stream operator for vectors.

Parameters
[in]vThe input vector.
Returns
The LogStream.

Definition at line 454 of file LogStream.hh.

References LogStream::getOutputStream(), and LogStream::isActive().

◆ operator<<() [4/6]

LogStream& operator<< ( const T &  arg)
inline

Templated stream operator.

Parameters
[in]argThe templated argument.
Returns
The LogStream.

Definition at line 441 of file LogStream.hh.

References LogStream::getOutputStream(), and LogStream::isActive().

◆ operator<<() [5/6]

LogStream& operator<< ( ios &(*)(std::ios &)  manip)
inline

Handle STL Setiosflags manipulator.

Parameters
[in]Theios manipulator.
Returns
The LogStream. Handle STL Resetiosflags manipulator.
Parameters
[in]Theios manipulator.
Returns
The LogStream. Handle STL Setbase manipulator.
Parameters
[in]Theios manipulator.
Returns
The LogStream. Handle STL Setprecision manipulator.
Parameters
[in]Theios manipulator.
Returns
The LogStream. Handle STL Setw manipulator.
Parameters
[in]Theios manipulator.
Returns
The LogStream. Handle ios class modifiers.
Parameters
[in]manipThe ios class modifier.
Returns
The LogStream.

Definition at line 416 of file LogStream.hh.

References LogStream::getOutputStream(), and LogStream::isActive().

◆ operator<<() [6/6]

LogStream& operator<< ( std::ios_base &(*)(std::ios_base &)  manip)
inline

Handle ios base class modifiers.

Parameters
[in]manipThe ios base class modifier.
Returns
The LogStream.

Definition at line 428 of file LogStream.hh.

References LogStream::getOutputStream(), and LogStream::isActive().

◆ precision() [1/2]

int precision ( ) const
inline

Get the precision.

Returns
The precision.

Definition at line 527 of file LogStream.hh.

References LogStream::getOutputStream(), and LogStream::isActive().

◆ precision() [2/2]

int precision ( int  v)
inline

Set the precision.

Parameters
[in]vThe precision.
Returns
The new precision.

Definition at line 536 of file LogStream.hh.

References LogStream::getOutputStream(), and LogStream::isActive().

◆ rdstate()

int rdstate ( ) const
inline

Get the read state.

Returns
The read state.

Definition at line 544 of file LogStream.hh.

References LogStream::getOutputStream(), and LogStream::isActive().

◆ setActive()

void setActive ( bool  active)
inlineprivate

Set whether this LogStream is active.

Parameters
[in]activeThe setting for enabling this LogStream to print messages.

Definition at line 608 of file LogStream.hh.

References LogStream::m_active.

Referenced by LogStream::operator<<().

◆ setCurrentLevel()

void setCurrentLevel ( LOG::ELevel  level)
inline

Set the current log level for messages.

Parameters
[in]levelThe log level.

Definition at line 159 of file LogStream.hh.

References LOG::level, and LogStream::m_currentMessageLevel.

Referenced by LogStream::operator<<().

◆ setf() [1/2]

long setf ( std::ios_base::fmtflags  _f,
std::ios_base::fmtflags  _m 
)
inline

Set the format flags.

Parameters
[in]_fThe format flags.
[in]_mThe mask containing the flags to be modified.
Returns
The new format flags.

Definition at line 578 of file LogStream.hh.

References LogStream::getOutputStream(), and LogStream::isActive().

◆ setf() [2/2]

long setf ( std::ios_base::fmtflags  v)
inline

Set the formatting flags.

Parameters
[in]vThe formatting flags.
Returns
The current set of formatting flags.

Definition at line 502 of file LogStream.hh.

References LogStream::getOutputStream(), and LogStream::isActive().

◆ setOutputFile()

void setOutputFile ( const std::string &  file)
inline

Redirect the messages to a file.

Parameters
[in]fileThe file name.

Definition at line 220 of file LogStream.hh.

References LogStream::m_fos, and LogStream::m_os.

Referenced by LogMessenger::SetNewValue().

◆ setOutputLevel()

void setOutputLevel ( const LOG::ELevel &  outputLevel)
inline

Set the output level.

Parameters
[in]outputLevelThe output level.

Definition at line 135 of file LogStream.hh.

References LogStream::m_outputLevel.

Referenced by EventSourceManager::EventSourceManager(), HepPDTManager::HepPDTManager(), and LogMessenger::SetNewValue().

◆ unsetf()

void unsetf ( std::ios_base::fmtflags  _l)
inline

Clears the format flags selected by the mask.

Parameters
[in]_lThe mask specifying which format flags to clear.

Definition at line 586 of file LogStream.hh.

References LogStream::getOutputStream(), and LogStream::isActive().

◆ verbose() [1/2]

LogStream& verbose ( )
inline

◆ verbose() [2/2]

void verbose ( const std::string &  mesg)
inline

Log a message at verbose level.

Parameters
[in]mesgThe message.

Definition at line 311 of file LogStream.hh.

References LogStream::log(), and LOG::verbose.

◆ warning() [1/2]

LogStream& warning ( )
inline

Set the current level to warning.

Returns
The LogStream.

Definition at line 254 of file LogStream.hh.

References LOG::warning.

Referenced by SlicApplication::initialize(), LcioManager::makeAutoname(), ModuleRegistry::registerModule(), and EventSourceManager::setupEventSource().

◆ warning() [2/2]

void warning ( const std::string &  mesg)
inline

Log a message at warning level.

Parameters
[in]mesgThe message.

Definition at line 327 of file LogStream.hh.

References LogStream::log(), and LOG::warning.

◆ width() [1/2]

int width ( ) const
inline

Get the current width setting.

Parameters
[in]Thewidth setting.

Definition at line 467 of file LogStream.hh.

References LogStream::getOutputStream(), and LogStream::isActive().

◆ width() [2/2]

int width ( int  v)
inline

Set the current width.

Parameters
[in]Thewidth setting.
Returns
The new width setting.

Definition at line 476 of file LogStream.hh.

References LogStream::getOutputStream(), and LogStream::isActive().

Friends And Related Function Documentation

◆ LogManager

friend class LogManager
friend

Give the LogManager full access to protected constructors.

Definition at line 103 of file LogStream.hh.

Member Data Documentation

◆ m_active

bool m_active
private

Definition at line 617 of file LogStream.hh.

Referenced by LogStream::isActive(), and LogStream::setActive().

◆ m_currentMessageLevel

LOG::ELevel m_currentMessageLevel
private

◆ m_fos

std::ofstream* m_fos
private

Definition at line 618 of file LogStream.hh.

Referenced by LogStream::setOutputFile().

◆ m_name

std::string m_name
private

Definition at line 613 of file LogStream.hh.

Referenced by LogStream::getName().

◆ m_os

ostream* m_os
private

Definition at line 616 of file LogStream.hh.

Referenced by LogStream::getOutputStream(), and LogStream::setOutputFile().

◆ m_outputLevel

LOG::ELevel m_outputLevel
private

Definition at line 614 of file LogStream.hh.

Referenced by LogStream::getOutputLevel(), and LogStream::setOutputLevel().


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