Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | Related Pages

streamlog::logstream Class Reference

Class defining a log stream that is used to print log messages depending on current log level. More...

#include <logstream.h>

List of all members.

Public Member Functions

void init (std::ostream &os, const std::string name)
 Initialize the logstream with an std::ostream, e.g.

template<class T> bool write ()
 True if next log message of the current level (class T ) will be written, i.e.

std::ostream & 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>().

template<class T> void addLevelName ()
 Adds a level name to the stream for setting the log level with a string through a scope class.


Protected Member Functions

void setLevel (unsigned level)
 Set the current level - user need to use a streamlog::logscope object to do this.

unsigned setLevel (const std::string &levelName)
 Set the current level through its name - only level previously made known to the stream through addLevelName will have an effect.

prefix_baseprefix ()
 Returns the prefix for the logbuffer object.

template<class T> bool check_level ()
 used internally by write<T>


Friends

class logscope
class logbuffer


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 )

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.

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:
Generated on Mon Jan 12 09:48:59 2009 for Marlin by doxygen 1.3.5