Main Page | Modules | Namespace List | Class Hierarchy | Class List | Namespace Members | Class Members

LogStream Class Reference

Log Stream Class. More...

#include <logStream.h>

List of all members.

Public Types

Enums
enum  LogStreamLevel { ERROR_LEVEL = 2000, WARNING_LEVEL = 1000, INFORMATION_LEVEL = 0 }
 Log levels. More...

Public Member Functions

Constructors and Destructors
 LogStream (LogStreamBuf *buf=0, bool delete_buf=true, bool associate_stdio=false)
 Constructor.
virtual ~LogStream ()
 Destructor.
Stream Methods
LogStreamBufrdbuf ()
 rdbuf method of ostream.
LogStreamBufoperator-> ()
 Arrow operator.
Loglevel management
void setLevel (int level)
 Assign a new log level.
int getLevel ()
 Return the current log level.
LogStreamlevel (int level)
 Set a temporary log level.
LogStreaminfo (int n=0)
 Log an information message.
LogStreamerror (int n=0)
 Log an error message.
LogStreamwarn (int n=0)
 Log an information message.
Associating Streams
void insert (std::ostream &s, int min_level=LogStreamBuf::MIN_LEVEL, int max_level=LogStreamBuf::MAX_LEVEL)
 Associate a new stream with this logstream.
void remove (std::ostream &s)
 Remove an association with a stream.
void insertNotification (std::ostream &s, LogStreamNotifier &target, int min_level=LogStreamBuf::MIN_LEVEL, int max_level=LogStreamBuf::MAX_LEVEL)
 Add a notification target.
void setMinLevel (const std::ostream &s, int min_level)
 Set the minimum log level of an associated stream.
void setMaxLevel (const std::ostream &s, int max_level)
 Set the maximum log level of an associated stream.
void setPrefix (const std::ostream &s, const string &prefix)
 Set prefix for output to this stream.
void disableOutput () throw ()
 Disable all output.
void enableOutput () throw ()
 Enable all output.
bool outputEnabled () const throw ()
 Is Output enabled?
void flush () throw ()
Message Buffer Management
void clear ()
 Clear the message buffer.
Size getNumberOfLines (int min_level=LogStreamBuf::MIN_LEVEL, int max_level=LogStreamBuf::MAX_LEVEL) const
 Return the number of lines.
string getLineText (const Index &index) const
 Return the text of a specific line.
Time getLineTime (const Index &index) const
 Return the log time of a specific line.
int getLineLevel (const Index &index) const
 Return the log level of a specific line.
list< int > filterLines (int min_level=LogStreamBuf::MIN_LEVEL, int max_level=LogStreamBuf::MAX_LEVEL, Time earliest=0, Time latest=LogStreamBuf::MAX_TIME, const string &s="") const
 Retrieve a list of indices of lines that match certain criteria.


Detailed Description

Log Stream Class.


Member Enumeration Documentation

enum LogStream::LogStreamLevel
 

Log levels.

Constants for the different predefined log levels. Use ERROR to indicate a severe error, WARNING to indicate a problem that could be fixed or is of minor importance, and INFORMATION for messages that do not indicate any problem (e.g. progress messages).

Enumeration values:
ERROR_LEVEL  Loglevels >= ERROR should be used to indicate errors.
WARNING_LEVEL  Loglevels >= WARNING should be used to indicate warnings.
INFORMATION_LEVEL  Loglevels >= INFORMATION indicate information messages.


Constructor & Destructor Documentation

LogStream::LogStream LogStreamBuf buf = 0,
bool  delete_buf = true,
bool  associate_stdio = false
 

Constructor.

Creates a new LogStream object that is not associated with any stream. If the argument associate_stdio is set to true, cout is associated with all messages of levels INFORMATION and WARNING , and cerr is associated with all messages of level ERROR .

Parameters:
buf 
delete_buf 
associate_stdio bool, default is false

virtual LogStream::~LogStream  )  [virtual]
 

Destructor.

Clears all message buffers.


Member Function Documentation

void LogStream::clear  ) 
 

Clear the message buffer.

This method removes all stored messages from the message buffer.

LogStream& LogStream::error int  n = 0  ) 
 

Log an error message.

This method is equivalent to level (LogStream::ERROR + n).

Parameters:
n the channel

list<int> LogStream::filterLines int  min_level = LogStreamBuf::MIN_LEVEL,
int  max_level = LogStreamBuf::MAX_LEVEL,
Time  earliest = 0,
Time  latest = LogStreamBuf::MAX_TIME,
const string &  s = ""
const
 

Retrieve a list of indices of lines that match certain criteria.

If a criterion is left empty, it is not used.

Parameters:
min_level the minimum level of messages
max_level the maximum level of messages
earliest (long) the time of messages to start filtering
latest (long) the time of messages to stop filtering
s a string to look for

int LogStream::getLevel  ) 
 

Return the current log level.

The LogStreamBuf object has an internal current log level (level_). It is set to 0 by the LogStreamBuf default constructor. This method returns rdbuf()->level_ if rdbuf() does not return a null pointer, 0 otherwise.

Returns:
int the current log level

int LogStream::getLineLevel const Index index  )  const
 

Return the log level of a specific line.

If the given line does not exists, {-1} is returned.

Parameters:
index the index of the message
Returns:
int the level

string LogStream::getLineText const Index index  )  const
 

Return the text of a specific line.

This method returns the content of a specific message without time and level.

Returns:
string the text of the message
Parameters:
index the index of the line

Time LogStream::getLineTime const Index index  )  const
 

Return the log time of a specific line.

Parameters:
index the index of the messages
Returns:
Time the time of the message

Size LogStream::getNumberOfLines int  min_level = LogStreamBuf::MIN_LEVEL,
int  max_level = LogStreamBuf::MAX_LEVEL
const
 

Return the number of lines.

This method retruns the number of lines in the buffer for a given range of levels.

If the range is omitted, the total number of messages is returned.
Returns:
Size the number of lines matching the log level range
Parameters:
min_level the minimum log level for the counted messages
max_level the maximum log level for the counted messages

LogStream& LogStream::info int  n = 0  ) 
 

Log an information message.

This method is equivalent to level (LogStream::INFORMATION + n).

Parameters:
n the channel

void LogStream::insert std::ostream &  s,
int  min_level = LogStreamBuf::MIN_LEVEL,
int  max_level = LogStreamBuf::MAX_LEVEL
 

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.

Parameters:
s a reference to the stream to be associated
MIN_LEVEL the minimum level of messages copied to this stream
MAX_LEVEL the maximum level of messages copied to this stream

LogStream& LogStream::level int  level  ) 
 

Set a temporary log level.

Using level, a temporary loglevel may be defined. It is valid unly until the next flush or endl is issued.

Use this command to log a single line with a certain log level.
Example: log << "log message 1" << endl;
log.level(4) << "log message 2" << endl;
log << "log message 3" << endl;
In this example, only the second message will be logged using level 4.
Returns:
LogStream the log stream
Parameters:
level the temporary log level

LogStreamBuf* LogStream::operator->  ) 
 

Arrow operator.

LogStreamBuf* LogStream::rdbuf  ) 
 

rdbuf method of ostream.

This method is needed to access the LogStreamBuf object.

void LogStream::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.

If the stream was not in the list of associated streams nothing will happen.
Parameters:
s the stream to be removed

void LogStream::setLevel int  level  ) 
 

Assign a new log level.

This method assigns a new loglevel which will be used for all messages sent to the LogStream after that call (except for messages which use the temporary loglevel set by level ).

void LogStream::setMaxLevel const std::ostream &  s,
int  max_level
 

Set the maximum log level of an associated stream.

This method changes the maximum log level of an already associated stream. However, if the stream is not associated, nothing will happen.

Parameters:
s the associated stream
max_level the new minimum level

void LogStream::setMinLevel const std::ostream &  s,
int  min_level
 

Set the minimum log level of an associated stream.

This method changes the minimum log level of an already associated stream. However, if the stream is not associated, nothing will happen.

Parameters:
s the associated stream
min_level the new minimum level

void LogStream::setPrefix const std::ostream &  s,
const 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.

The following format tags are recognized:
  • l loglevel
  • y message type ("Error", "Warning", "Information", "-")
  • T time (HH:MM:SS)
  • t time in short format (HH:MM)
  • D date (DD.MM.YYYY)
  • d date in short format (DD.MM.)
  • S time and date (DD.MM.YYYY, HH:MM:SS)
  • s time and date in short format (DD.MM., HH:MM)
  • % percent sign (escape sequence)

LogStream& LogStream::warn int  n = 0  ) 
 

Log an information message.

This method is equivalent to level (LogStream::WARNING + n).

Parameters:
n the channel