OpenMS  2.8.0
Classes | Friends | List of all members
LogStreamBuf Class Reference

Stream buffer used by LogStream. More...

#include <OpenMS/CONCEPT/LogStream.h>

Inheritance diagram for LogStreamBuf:
[legend]
Collaboration diagram for LogStreamBuf:
[legend]

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 (std::string log_level=UNKNOWN_LOG_LEVEL)
 
 ~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_
 
std::string level_
 
std::list< StreamStructstream_list_
 
std::string incomplete_line_
 
void setLevel (std::string level)
 
std::string getLevel ()
 
void clearCache ()
 
void distribute_ (std::string outstring)
 Distribute a new message to connected streams. More...
 
std::string expandPrefix_ (const std::string &prefix, time_t time) const
 Interpret the prefix format string and return the expanded prefix. More...
 

Caching

Size log_cache_counter_
 
std::map< std::string, LogCacheStructlog_cache_
 Cache of the last two log messages. More...
 
std::map< Size, std::string > log_time_cache_
 Cache of the occurrence sequence of the last two log messages. More...
 
bool isInCache_ (std::string const &line)
 Checks if the line is already in the cache. More...
 
std::string addToCache_ (std::string const &line)
 
Size getNextLogCounter_ ()
 Returns the next free index for a log message. More...
 
int syncLF_ ()
 Non-lock acquiring sync function called in the d'tor. More...
 

Detailed Description

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.


Class Documentation

◆ OpenMS::Logger::LogStreamBuf::LogCacheStruct

struct OpenMS::Logger::LogStreamBuf::LogCacheStruct

Holds a counter of occurrences and an index for the occurrence sequence of the corresponding log message.

Collaboration diagram for LogStreamBuf::LogCacheStruct:
[legend]
Class Members
int counter
Size timestamp

Constructor & Destructor Documentation

◆ LogStreamBuf()

LogStreamBuf ( std::string  log_level = UNKNOWN_LOG_LEVEL)
explicit

Create a new LogStreamBuf object and set the level to log_level

Parameters
log_levelThe log level of the LogStreamBuf (default is unknown)

◆ ~LogStreamBuf()

~LogStreamBuf ( )
override

Destruct the buffer and free all stored messages strings.

Member Function Documentation

◆ addToCache_()

std::string addToCache_ ( std::string const &  line)
protected

Adds the new line to the cache and removes an old one if necessary

Parameters
lineThe Log message that should be added to the cache
Returns
An additional massage if a re-occurring message was removed from the cache

◆ clearCache()

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

◆ distribute_()

void distribute_ ( std::string  outstring)
protected

Distribute a new message to connected streams.

◆ expandPrefix_()

std::string expandPrefix_ ( const std::string &  prefix,
time_t  time 
) const
protected

Interpret the prefix format string and return the expanded prefix.

◆ getLevel()

std::string getLevel ( )

Returns the LogLevel of this LogStream

◆ getNextLogCounter_()

Size getNextLogCounter_ ( )
protected

Returns the next free index for a log message.

◆ isInCache_()

bool isInCache_ ( std::string const &  line)
protected

Checks if the line is already in the cache.

◆ overflow()

int overflow ( int  c = -1)
override

This method calls sync and streambuf::overflow(c) to prevent a buffer overflow.

◆ setLevel()

void setLevel ( std::string  level)

Set the level of the LogStream

Parameters
levelThe new LogLevel

◆ sync()

int sync ( )
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_.

◆ syncLF_()

int syncLF_ ( )
protected

Non-lock acquiring sync function called in the d'tor.

Friends And Related Function Documentation

◆ LogStream

friend class LogStream
friend

Member Data Documentation

◆ incomplete_line_

std::string incomplete_line_
protected

◆ level_

std::string level_
protected

◆ log_cache_

std::map<std::string, LogCacheStruct> log_cache_
protected

Cache of the last two log messages.

◆ log_cache_counter_

Size log_cache_counter_
protected

Sequential counter to remember the sequence of occurrence of the cached log messages

◆ log_time_cache_

std::map<Size, std::string> log_time_cache_
protected

Cache of the occurrence sequence of the last two log messages.

◆ MAX_TIME

const time_t MAX_TIME
static

◆ pbuf_

char* pbuf_
protected

◆ stream_list_

std::list<StreamStruct> stream_list_
protected

◆ UNKNOWN_LOG_LEVEL

const std::string UNKNOWN_LOG_LEVEL
static