OpenMS
2.6.0
|
Log Stream Class. More...
#include <OpenMS/CONCEPT/LogStream.h>
Public Member Functions | |
Constructors and Destructors | |
LogStream (LogStreamBuf *buf=nullptr, bool delete_buf=true, std::ostream *stream=nullptr) | |
~LogStream () override | |
Clears all message buffers. More... | |
Stream Methods | |
LogStreamBuf * | rdbuf () |
LogStreamBuf * | operator-> () |
Arrow operator. More... | |
Level methods | |
void | setLevel (std::string level) |
std::string | getLevel () |
Associating Streams | |
typedef std::list< LogStreamBuf::StreamStruct >::iterator | StreamIterator |
bool | delete_buffer_ |
void | insert (std::ostream &s) |
void | remove (std::ostream &s) |
void | insertNotification (std::ostream &s, LogStreamNotifier &target) |
Add a notification target. More... | |
void | setPrefix (const std::ostream &s, const std::string &prefix) |
void | setPrefix (const std::string &prefix) |
Set prefix of all output streams, details see setPrefix method with ostream. More... | |
void | flush () |
StreamIterator | findStream_ (const std::ostream &stream) |
bool | hasStream_ (std::ostream &stream) |
bool | bound_ () const |
Log Stream Class.
Defines a log stream which features a cache and some formatting. For the developer, however, only some macros are of interest which will push the message that follows them into the appropriate stream:
Macros:
To use a specific logger of a log level simply use it as cerr or cout:
OPENMS_LOG_ERROR << " A bad error occurred ..."
Which produces an error message in the log.
|
private |
LogStream | ( | LogStreamBuf * | buf = nullptr , |
bool | delete_buf = true , |
||
std::ostream * | stream = nullptr |
||
) |
Creates a new LogStream object that is not associated with any stream. If the argument stream
is set to an output stream (e.g. cout
) all output is send to that stream.
buf | |
delete_buf | |
stream |
|
override |
Clears all message buffers.
|
private |
|
private |
void flush | ( | ) |
std::string getLevel | ( | ) |
Returns the LogLevel of this LogStream
|
private |
void insert | ( | std::ostream & | s | ) |
Associate a new stream with this logstream. This method inserts a new stream into the list of associated streams and sets the corresponding minimum and maximum log levels. Any message that is subsequently logged, will be copied to this stream if its log level is between min_level
and max_level
. If min_level
and max_level
are omitted, all messages are copied to this stream. If min_level
and max_level
are equal, this function can be used to listen to a specified channel.
s | a reference to the stream to be associated |
Referenced by main().
void insertNotification | ( | std::ostream & | s, |
LogStreamNotifier & | target | ||
) |
Add a notification target.
LogStreamBuf* operator-> | ( | ) |
Arrow operator.
LogStreamBuf* rdbuf | ( | ) |
rdbuf method of ostream. This method is needed to access the LogStreamBuf object.
void remove | ( | std::ostream & | s | ) |
Remove an association with a stream.
Remove a stream from the stream list and avoid the copying of new messages to this stream.
s | the stream to be removed |
void setLevel | ( | std::string | level | ) |
Set the level of the LogStream
level | The new LogLevel |
void setPrefix | ( | const std::ostream & | s, |
const std::string & | prefix | ||
) |
Set prefix for output to this stream. Each line written to the stream will be prefixed by this string. The string may also contain trivial format specifiers to include loglevel and time/date of the logged message.
s | The stream that will be prefixed. |
prefix | The prefix used for the stream. |
void setPrefix | ( | const std::string & | prefix | ) |
Set prefix of all output streams, details see setPrefix method with ostream.
|
private |
flag needed by the destructor to decide whether the streambuf has to be deleted. If the default ctor is used to create the LogStreamBuf, delete_buffer_ is set to true and the ctor also deletes the buffer.