![]() |
OpenMS
|
Stream buffer used by LogStream. More...
#include <OpenMS/CONCEPT/LogStream.h>
Classes | |
| struct | LogCacheStruct |
| Holds a counter of occurrences and an index for the occurrence sequence of the corresponding log message. More... | |
| struct | StreamStruct |
| Holds a stream that is connected to the LogStream. It also includes the minimum and maximum level at which the LogStream redirects messages to this stream. More... | |
Public Member Functions | |
Constructors and Destructors | |
| LogStreamBuf (const std::string &log_level=UNKNOWN_LOG_LEVEL, Colorizer *col=nullptr) | |
| LogStreamBuf (LogStreamBuf *source_buf, Colorizer *col=nullptr) | |
| ~LogStreamBuf () override | |
Stream methods | |
| int | sync () override |
| int | overflow (int c=-1) override |
Static Public Attributes | |
Constants | |
| static const time_t | MAX_TIME |
| static const std::string | UNKNOWN_LOG_LEVEL |
Friends | |
| class | LogStream |
Level methods | |
| char * | pbuf_ = nullptr |
| std::string | level_ |
| std::list< StreamStruct > | stream_list_ |
| Destinations of this buffer (for a following buffer: derived from parent_, own_streams_ and hidden_ids_) | |
| std::string | incomplete_line_ |
| LogStreamBuf * | parent_ = nullptr |
| Buffer whose destinations this buffer follows (the global buffer of a thread-local one), or nullptr. | |
| std::atomic< Size > | version_ {0} |
| Incremented whenever stream_list_ changes, so that following buffers know when to update. | |
| Size | parent_version_ = 0 |
| version_ of parent_ that stream_list_ reflects | |
| std::list< StreamStruct > | own_streams_ |
| Destinations inserted into this following buffer; they replace parent_'s entry for the same stream. | |
| std::vector< Size > | hidden_ids_ |
| std::vector< const std::ostream * > | guarded_streams_ |
| Streams that a LogSinkGuard suppresses on this following buffer (one entry per guard), however they are inserted. | |
| Colorizer * | colorizer_ = nullptr |
| void | setLevel (std::string level) |
| std::string | getLevel () |
| void | clearCache () |
| void | distribute_ (const std::string &outstring) |
| Distribute a new message to connected streams. | |
| void | distributeNew_ (const std::string &line) |
| std::string | expandPrefix_ (const std::string &prefix, time_t time) const |
| Interpret the prefix format string and return the expanded prefix. | |
| std::list< StreamStruct > & | getStreamList_ () |
| Returns the stream list (owned or shared) | |
| const std::list< StreamStruct > & | getStreamList_ () const |
| void | updateFromParent_ () |
| Updates stream_list_ if parent_ changed its destinations since the last update. Locks the sink mutex. | |
| void | updateFromParentLocked_ () |
| Same as updateFromParent_(), but the caller holds the sink mutex. | |
| void | rebuildStreamList_ () |
| Rebuilds stream_list_ from parent_'s destinations and this buffer's own changes. The caller holds the sink mutex. | |
| bool | guarded_ (const std::ostream *stream) const |
Is stream suppressed by a LogSinkGuard on this following buffer (see guarded_streams_)? | |
| std::list< StreamStruct > & | prefixableStreams_ () |
| Entries whose prefix may be changed: stream_list_, or own_streams_ for a following buffer (the prefix of parent_'s destinations is set on parent_) | |
| void | destinationsChanged_ () |
| Publishes a change of the destinations to following buffers (or rebuilds stream_list_). The caller holds the sink mutex. | |
Caching | |
| Size | log_cache_counter_ = 0 |
| std::map< std::string, LogCacheStruct > | log_cache_ |
| Cache of the last two log messages. | |
| std::map< Size, std::string > | log_time_cache_ |
| Cache of the occurrence sequence of the last two log messages. | |
| bool | isInCache_ (std::string const &line) |
| Checks if the line is already in the cache. | |
| std::string | addToCache_ (std::string const &line) |
| Size | getNextLogCounter_ () |
| Returns the next free index for a log message. | |
| int | syncLF_ () |
| Non-lock acquiring sync function called in the d'tor. | |
| std::vector< std::string > | repeatSummaries_ () const |
| "<message> occurred N times" for each cached message that was repeated | |
| void | forgetRepeatsAfterChange_ (const std::vector< Size > &previous) |
| std::vector< Size > | destinations_ () const |
| The destinations in stream_list_ (their StreamStruct::id), sorted. | |
| void | write_ (StreamStruct &s, const std::string &line) |
Writes line to the destination s, with its prefix and color. The caller holds the sink mutex. | |
Stream buffer used by LogStream.
This class implements the low level behavior of LogStream . It takes care of the buffers and stores the lines written into the LogStream object. It also contains a list of streams that are associated with the LogStream object. This list contains pointers to the streams and their minimum and maximum log level. Each line entered in the LogStream is marked with its time (in fact, the time LogStreamBuf::sync was called) and its loglevel. The loglevel is determined by either the current loglevel (as set by LogStream::setLevel or a temporary level (as set by LogStream::level for a single line only). For each line stored, the list of associated streams is checked whether the loglevel falls into the range declared by the stream's minimum and maximum level. If this condition is met, the logline (with its prefix, see LogStream::setPrefix ) is also copied to the associated stream and this stream is flushed, too.
| struct OpenMS::Logger::LogStreamBuf::LogCacheStruct |
Holds a counter of occurrences and an index for the occurrence sequence of the corresponding log message.
| Class Members | ||
|---|---|---|
| int | counter | |
| Size | timestamp | |
| LogStreamBuf | ( | const std::string & | log_level = UNKNOWN_LOG_LEVEL, |
| Colorizer * | col = nullptr |
||
| ) |
Create a new LogStreamBuf object and set the level to log_level
| [in] | log_level | The log level of the LogStreamBuf (default is unknown) |
| [in] | col | If messages should be colored, provide a colorizer here |
| LogStreamBuf | ( | LogStreamBuf * | source_buf, |
| Colorizer * | col = nullptr |
||
| ) |
Create a LogStreamBuf that writes to the destinations of another LogStreamBuf.
This constructor is used for thread-local logging: each thread has its own buffer (for thread safety) that follows the destinations of the global LogStream instance, including changes made after this buffer was created. Destinations inserted into or removed from the LogStream of this buffer only affect this buffer (see LogStream::insert()).
| [in] | source_buf | The LogStreamBuf whose destinations should be followed |
| [in] | col | If messages should be colored, provide a colorizer here |
|
override |
Destruct the buffer and free all stored messages strings.
|
protected |
Adds the new line to the cache and removes an old one if necessary
| [in] | line | The Log message that should be added to the cache |
| void clearCache | ( | ) |
Checks if some of the cached entries where sent more then once to the LogStream and (if necessary) prints a corresponding messages into all affected Logs
|
protected |
The destinations in stream_list_ (their StreamStruct::id), sorted.
|
protected |
Publishes a change of the destinations to following buffers (or rebuilds stream_list_). The caller holds the sink mutex.
|
protected |
Distribute a new message to connected streams.
|
protected |
Adds line, which is not in the cache, to the cache and distributes it, after the repeat count of a message it evicts. Under the sink mutex and after applying changes of parent_'s destinations, so that the count goes only to destinations that got the repeated message.
|
protected |
Interpret the prefix format string and return the expanded prefix.
|
protected |
After stream_list_ changed from the destinations previous (see destinations_()): writes the pending repeat counts to the destinations that remain and clears the cache, so that a new destination gets every message. The caller holds the sink mutex.
| std::string getLevel | ( | ) |
Returns the LogLevel of this LogStream
|
protected |
Returns the next free index for a log message.
|
protected |
Returns the stream list (owned or shared)
|
protected |
|
protected |
Is stream suppressed by a LogSinkGuard on this following buffer (see guarded_streams_)?
|
protected |
Checks if the line is already in the cache.
|
override |
This method calls sync and streambuf::overflow(c) to prevent a buffer overflow.
|
protected |
Entries whose prefix may be changed: stream_list_, or own_streams_ for a following buffer (the prefix of parent_'s destinations is set on parent_)
|
protected |
Rebuilds stream_list_ from parent_'s destinations and this buffer's own changes. The caller holds the sink mutex.
|
protected |
"<message> occurred N times" for each cached message that was repeated
| void setLevel | ( | std::string | level | ) |
Set the level of the LogStream
| [in] | level | The new LogLevel |
|
override |
This method is called as soon as the ostream is flushed (especially this method is called by flush or endl). It transfers the contents of the streambufs putbuffer into a logline if a newline or linefeed character is found in the buffer ("\n" or "\r" resp.). The line is then removed from the putbuffer. Incomplete lines (not terminated by "\n" / "\r" are stored in incomplete_line_.
|
protected |
Non-lock acquiring sync function called in the d'tor.
|
protected |
Updates stream_list_ if parent_ changed its destinations since the last update. Locks the sink mutex.
|
protected |
Same as updateFromParent_(), but the caller holds the sink mutex.
|
protected |
Writes line to the destination s, with its prefix and color. The caller holds the sink mutex.
|
friend |
|
protected |
optional Colorizer to color the output to stdout/stdcerr (if attached)
|
protected |
Streams that a LogSinkGuard suppresses on this following buffer (one entry per guard), however they are inserted.
|
protected |
Destinations of parent_ (their StreamStruct::id) removed from this following buffer. Kept when parent_ removes them: a LogSinkGuard on parent_ restores a destination with its id, and ids are never reused.
|
protected |
|
protected |
|
protected |
Cache of the last two log messages.
|
protected |
Sequential counter to remember the sequence of occurrence of the cached log messages
|
protected |
Cache of the occurrence sequence of the last two log messages.
|
static |
|
protected |
Destinations inserted into this following buffer; they replace parent_'s entry for the same stream.
|
protected |
Buffer whose destinations this buffer follows (the global buffer of a thread-local one), or nullptr.
|
protected |
version_ of parent_ that stream_list_ reflects
|
protected |
|
protected |
Destinations of this buffer (for a following buffer: derived from parent_, own_streams_ and hidden_ids_)
|
static |
|
protected |
Incremented whenever stream_list_ changes, so that following buffers know when to update.