#include <logstream.h>
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_base * | prefix () |
Returns the prefix for the logbuffer object. | |
template<class T> bool | check_level () |
used internally by write<T> | |
Friends | |
class | logscope |
class | logbuffer |
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.
|
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.
|
|
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. |
|
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. |