BALL  1.4.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Private Types | Private Member Functions | Private Attributes | List of all members
BALL::LogStream Class Reference

#include <BALL/COMMON/logStream.h>

Inheritance diagram for BALL::LogStream:

Public Types

Enums
enum  LogStreamLevel { ERROR_LEVEL = 2000, WARNING_LEVEL = 1000, INFORMATION_LEVEL = 0 }
 

Public Member Functions

Constructors and Destructors
 LogStream (LogStreamBuf *buf=0, bool delete_buf=true, bool associate_stdio=false)
 
virtual ~LogStream ()
 
Stream Methods
LogStreamBufrdbuf ()
 
LogStreamBufoperator-> ()
 
Loglevel management
void setLevel (int level)
 
int getLevel ()
 
LogStreamlevel (int level)
 
LogStreaminfo (int n=0)
 
LogStreamerror (int n=0)
 
LogStreamwarn (int n=0)
 
Associating Streams
void insert (std::ostream &s, int min_level=LogStreamBuf::MIN_LEVEL, int max_level=LogStreamBuf::MAX_LEVEL)
 
void remove (std::ostream &s)
 
void insertNotification (std::ostream &s, LogStreamNotifier &target, int min_level=LogStreamBuf::MIN_LEVEL, int max_level=LogStreamBuf::MAX_LEVEL)
 
void setMinLevel (const std::ostream &s, int min_level)
 
void setMaxLevel (const std::ostream &s, int max_level)
 
void setPrefix (const std::ostream &s, const string &prefix)
 
void disableOutput ()
 Disable all output. More...
 
void enableOutput ()
 Enable all output. More...
 
bool outputEnabled () const
 Is Output enabled? More...
 
std::ostream & flush ()
 
Message Buffer Management
void clear ()
 
Size getNumberOfLines (int min_level=LogStreamBuf::MIN_LEVEL, int max_level=LogStreamBuf::MAX_LEVEL) const
 
string getLineText (const Index &index) const
 
Time getLineTime (const Index &index) const
 
int getLineLevel (const Index &index) const
 
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
 

Private Types

typedef std::list
< LogStreamBuf::StreamStruct >
::iterator 
StreamIterator
 

Private Member Functions

StreamIterator findStream_ (const std::ostream &stream)
 
bool hasStream_ (std::ostream &stream)
 
bool bound_ () const
 

Private Attributes

bool delete_buffer_
 
bool disable_output_
 

Detailed Description

Log Stream Class.

Definition at line 259 of file logStream.h.

Member Typedef Documentation

typedef std::list<LogStreamBuf::StreamStruct>::iterator BALL::LogStream::StreamIterator
private

Definition at line 537 of file logStream.h.

Member Enumeration Documentation

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

Enumerator
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

Definition at line 276 of file logStream.h.

Constructor & Destructor Documentation

BALL::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_stdiobool, default is false
virtual BALL::LogStream::~LogStream ( )
virtual

Destructor. Clears all message buffers.

Member Function Documentation

bool BALL::LogStream::bound_ ( ) const
private
void BALL::LogStream::clear ( )

Clear the message buffer. This method removes all stored messages from the message buffer.

void BALL::LogStream::disableOutput ( )

Disable all output.

void BALL::LogStream::enableOutput ( )

Enable all output.

LogStream& BALL::LogStream::error ( int  n = 0)

Log an error message. This method is equivalent to level (LogStream::ERROR + n).

Parameters
nthe channel
list<int> BALL::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_levelthe minimum level of messages
max_levelthe maximum level of messages
earliest(long) the time of messages to start filtering
latest(long) the time of messages to stop filtering
sa string to look for
StreamIterator BALL::LogStream::findStream_ ( const std::ostream &  stream)
private
std::ostream& BALL::LogStream::flush ( )
Flush the LogStream.\n

This function overloads std::ostream::flush().

int BALL::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 BALL::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
indexthe index of the message
Returns
int the level
string BALL::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
indexthe index of the line
Time BALL::LogStream::getLineTime ( const Index index) const

Return the log time of a specific line

Parameters
indexthe index of the messages
Returns
Time the time of the message
Size BALL::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_levelthe minimum log level for the counted messages
max_levelthe maximum log level for the counted messages
bool BALL::LogStream::hasStream_ ( std::ostream &  stream)
private
LogStream& BALL::LogStream::info ( int  n = 0)

Log an information message. This method is equivalent to level (LogStream::INFORMATION + n).

Parameters
nthe channel
void BALL::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
sa reference to the stream to be associated
MIN_LEVELthe minimum level of messages copied to this stream
MAX_LEVELthe maximum level of messages copied to this stream
void BALL::LogStream::insertNotification ( std::ostream &  s,
LogStreamNotifier target,
int  min_level = LogStreamBuf::MIN_LEVEL,
int  max_level = LogStreamBuf::MAX_LEVEL 
)

Add a notification target

LogStream& BALL::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
levelthe temporary log level
LogStreamBuf* BALL::LogStream::operator-> ( )

Arrow operator.

bool BALL::LogStream::outputEnabled ( ) const

Is Output enabled?

LogStreamBuf* BALL::LogStream::rdbuf ( )

rdbuf method of ostream. This method is needed to access the LogStreamBuf object.

void BALL::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
sthe stream to be removed
void BALL::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 BALL::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
sthe associated stream
max_levelthe new minimum level
void BALL::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
sthe associated stream
min_levelthe new minimum level
void BALL::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& BALL::LogStream::warn ( int  n = 0)

Log an information message. This method is equivalent to level (LogStream::WARNING + n).

Parameters
nthe channel

Member Data Documentation

bool BALL::LogStream::delete_buffer_
private

Definition at line 547 of file logStream.h.

bool BALL::LogStream::disable_output_
private

Definition at line 548 of file logStream.h.