Luiza  v03-01
Public Member Functions | Protected Member Functions | List of all members
streamlog::logstream Class Reference

#include <logstream.h>

Public Member Functions

void init (std::ostream &os, const std::string name)
 
template<class T >
bool write ()
 
template<class T >
bool would_write ()
 
std::ostream & operator() ()
 
template<class T >
void addLevelName ()
 

Protected Member Functions

void setLevel (unsigned level)
 
unsigned setLevel (const std::string &levelName)
 
prefix_baseprefix ()
 
template<class T >
bool check_level ()
 

Detailed Description

Class defining a log stream that is used to print log messages depending on current log level. Can be initialized with any std::ostream, typically either std::cout or an std::ofstream file handler. There is one global instance of this class defined in the library: logstream::out
Typically only this instance is needed, e.g.:

  // in int main() :
  streamlog::out.init( std::cout, argv[0] ) ;
  //...
  if( streamlog::out.write< streamlog::DEBUG1 >() )
     streamlog::out() << " this message will only be printed if level >= DEBUG1::level " 
                      << std::endl ;
  // or the same, simply using a macro:
  streamlog_out( DEBUG )  << " this message will only be printed if level >= DEBUG1::level " 
                          << std::endl ;

Note that with the above calling sequence or the macro no runtime overhead is created if streamlog::DEBUG1::active is false and else if the log level is smaller than streamlog::DEBUG1::level no formatting of the message will happen, i.e. also very little runtime cost is involved.
the behaviour of the logstream, i.e. the current log level and log scope name can be changed only through an object of streamlog::logscope.

See also
logstream::write()
logscope
Author
F. Gaede, DESY
Version
Id
logstream.h,v 1.3 2007-08-08 13:08:34 gaede Exp

Member Function Documentation

template<class T >
void streamlog::logstream::addLevelName ( )
inline

Adds a level name to the stream for setting the log level with a string through a scope class. Only names added with this method will have an effect - other log levels can only be activated with logstream::logscope::setLevel<T>(). Useful for framework programs where the log level can be changed via a steering parameter.

See also
logstream::logscope::setLevel(const std::string levelName )
template<class T >
bool streamlog::logstream::check_level ( )
inlineprotected

used internally by write<T>

void streamlog::logstream::init ( std::ostream &  os,
const std::string  name 
)

Initialize the logstream with an std::ostream, e.g. std::cout and the main scope name, e.g. argv[0]. Only first call to this method has an effect, subsequent calls are ignored.

std::ostream & streamlog::logstream::operator() ( )

Return the actual std::ostream where the message should be writen to - will return a nullstream unless prepended by a successfull call to write<MESSAGELEVEL>()

prefix_base* streamlog::logstream::prefix ( )
inlineprotected

Returns the prefix for the logbuffer object

Referenced by streamlog::logbuffer::overflow(), streamlog::logscope::setName(), and streamlog::logscope::~logscope().

void streamlog::logstream::setLevel ( unsigned  level)
inlineprotected

Set the current level - user need to use a streamlog::logscope object to do this.

Referenced by streamlog::logscope::setLevel(), and streamlog::logscope::~logscope().

unsigned streamlog::logstream::setLevel ( const std::string &  levelName)
protected

Set the current level through its name - only level previously made known to the stream through addLevelName will have an effect.

template<class T >
bool streamlog::logstream::would_write ( )
inline

True if next log message of the current level (class T ) would be written

  • can be used to conditionally execute code blocks that are needed before writing to the outstream.
template<class T >
bool streamlog::logstream::write ( )
inline

True if next log message of the current level (class T ) will be written, i.e. the next call to std::ostream& operator()() will return a valid outstream.


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