Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Friends

LogStreamBuf Class Reference

Stream buffer used by LogStream. More...

#include <OpenMS/CONCEPT/LogStream.h>

Inheritance diagram for LogStreamBuf:
streambuf

List of all members.

Classes

struct  LogCacheStruct
 Holds a counter of occurences and an index for the occurence 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

void clearCache ()
Constructors and Destructors

 LogStreamBuf (std::string log_level=UNKNOWN_LOG_LEVEL)
virtual ~LogStreamBuf ()
Stream methods

virtual int sync ()
virtual int overflow (int c=-1)
Level methods

void setLevel (std::string level)
std::string getLevel ()

Static Public Attributes

Constants

static const time_t MAX_TIME
static const std::string UNKNOWN_LOG_LEVEL

Protected Member Functions

void distribute_ (std::string outstring)
 Distribute a new message to connected streams.
std::string expandPrefix_ (const std::string &prefix, time_t time) const
 Interpret the prefix format string and return the expanded prefix.

Protected Attributes

char * pbuf_
std::string level_
std::list< StreamStructstream_list_
std::string incomplete_line_

Friends

class LogStream

Caching



Size log_cache_counter_
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 occurence 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.

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.


Constructor & Destructor Documentation

LogStreamBuf ( std::string  log_level = UNKNOWN_LOG_LEVEL  )  [explicit]

Create a new LogStreamBuf object and set the level to log_level

Parameters:
log_level The log level of the LogStreamBuf (default is unknown)
virtual ~LogStreamBuf (  )  [virtual]

Destruct the buffer and free all stored messages strings.


Member Function Documentation

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

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

Parameters:
line The Log message that should be added to the cache
Returns:
An additional massage if a reoccuring message was removed from 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

void distribute_ ( std::string  outstring  )  [protected]

Distribute a new message to connected streams.

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

Interpret the prefix format string and return the expanded prefix.

std::string getLevel (  ) 

Returns the LogLevel of this LogStream

Size getNextLogCounter_ (  )  [protected]

Returns the next free index for a log message.

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

Checks if the line is already in the cache.

virtual int overflow ( int  c = -1  )  [virtual]

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

void setLevel ( std::string  level  ) 

Set the level of the LogStream

Parameters:
level The new LogLevel
virtual int sync (  )  [virtual]

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_.


Friends And Related Function Documentation

friend class LogStream [friend]

Member Data Documentation

std::string incomplete_line_ [protected]
std::string level_ [protected]
std::map<std::string, LogCacheStruct> log_cache_ [protected]

Cache of the last two log messages.

Size log_cache_counter_ [protected]

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

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

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

const time_t MAX_TIME [static]
char* pbuf_ [protected]
std::list<StreamStruct> stream_list_ [protected]
const std::string UNKNOWN_LOG_LEVEL [static]

OpenMS / TOPP release 1.10.0 Documentation generated on Thu Mar 7 2013 09:43:00 using doxygen 1.7.1