Luiza
v03-01
|
#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_base * | prefix () |
template<class T > | |
bool | check_level () |
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.
|
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.
|
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>()
|
inlineprotected |
Returns the prefix for the logbuffer object
Referenced by streamlog::logbuffer::overflow(), streamlog::logscope::setName(), and streamlog::logscope::~logscope().
|
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().
|
protected |
Set the current level through its name - only level previously made known to the stream through addLevelName will have an effect.
|
inline |
True if next log message of the current level (class T ) would be written
|
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.