COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
LogStream Class Reference

Manages a log stream. More...

#include <LogStream.hpp>

Public Types

enum  LogTag { ENDLINE }
 Special message tag. More...
 
enum  LogDestination { SCREEN = 1, FILE = 2, STRING = 4, SYNC_SCREEN = 8 }
 Message destination. More...
 

Public Member Functions

 LogStream (const std::string &streamName, LogLevel level=INFO)
 Constructor. More...
 
 ~LogStream ()
 Destructor. More...
 
void flush ()
 Flushes the stream contents. More...
 
LogStreamoperator<< (LogLevel level)
 Overrides operator << for LogLevel type. More...
 
LogStreamoperator<< (LogTag tag)
 Overrides operator << for #Logtag type. More...
 
LogStreamoperator<< (const CodeLocation &codeLoction)
 Overrides operator << for LogLevel type. More...
 
template<typename T >
LogStreamoperator<< (const T &t)
 Overrides operator << for any type. More...
 
void set_log_level (const Uint level)
 Sets new default level. More...
 
void set_log_level (LogDestination destination, const Uint level)
 Sets new default level to the specified destination. More...
 
void set_filter (LogLevel level)
 Sets new default level. More...
 
void set_filter (LogDestination destination, LogLevel level)
 Sets new default level to the specified destination. More...
 
LogLevel get_filter (LogDestination destination) const
 Gives the default log level of a specified destination. More...
 
void useDestination (LogDestination destination, bool use)
 Modifies the use policy of a destination. More...
 
bool isDestinationUsed (LogDestination destination) const
 Gives the use policy of a destination. More...
 
void setStamp (LogDestination destination, const std::string &stampFormat)
 Sets a stamp format to a specified destination. More...
 
std::string getStamp (LogDestination destination)
 Gives the stamp format of a specified destination. More...
 
void setStamp (const std::string &stampFormat)
 Sets a stamp format to all destinations. More...
 
void setFilterRankZero (LogDestination dest, bool filterRankZero)
 Enables or disables the filter on MPI rank zero on a destination. More...
 
void setFilterRankZero (bool filterRankZero)
 Enables or disables the filter on MPI rank zero on all destinations. More...
 
bool getFilterRankZero (LogDestination dest) const
 Checks whether the filter for rank 0 is set on the specified destination. More...
 
void setFile (const boost::iostreams::file_descriptor_sink &fileDescr)
 Sets the file. More...
 
bool isFileOpen () const
 Cheks whether the file is set. More...
 
void addStringForwarder (LogStringForwarder *forwarder)
 Appends a string forwarder to the forwarder list. More...
 
void removeStringForwarder (LogStringForwarder *forwarder)
 Removes a string from the forwarder list. More...
 
unsigned int getStringForwarderCount () const
 Gives the number of string forwarders the stream contains. More...
 

Private Member Functions

LogLevelFiltergetLevelFilter (LogDestination dest) const
 Gives the level filter of a destination. More...
 
LogStampFiltergetStampFilter (LogDestination dest) const
 Gives the stamp filter of a destination. More...
 

Private Attributes

std::map< LogDestination, boost::iostreams::filtering_ostream * > m_destinations
 Destinations. More...
 
std::list< LogStringForwarder * > m_stringForwarders
 The forwarder list. More...
 
std::map< LogDestination, bool > m_usedDests
 Use policies. More...
 
std::map< LogDestination, bool > m_filterRankZero
 Rank zero filter. More...
 
std::string m_buffer
 Buffer for STRING destination. More...
 
std::string m_streamName
 Stream name. More...
 
LogLevel m_filter_level
 Default value. More...
 
bool m_flushed
 Flush status. More...
 

Detailed Description

Manages a log stream.

Author
Quentin Gasper

Definition at line 30 of file LogStream.hpp.

Member Enumeration Documentation

Message destination.

Enumerator
SCREEN 

Standard output.

FILE 

File.

STRING 

A string buffer.

SYNC_SCREEN 

Standard output (with MPI synchronization)

Note
If one processor will output more than another, that processor will wait FOREVER for synchronization. Use with care!

Definition at line 47 of file LogStream.hpp.

enum LogTag

Special message tag.

For now, the only available tag is ENDLINE.

Enumerator
ENDLINE 

Indicates the end of a message.

This tag must be used to flush stream buffers and must end each log message to guarantee that the stream buffers are flushed.

Definition at line 37 of file LogStream.hpp.

Constructor & Destructor Documentation

LogStream ( const std::string &  streamName,
LogLevel  level = INFO 
)

Constructor.

Parameters
fileStreamThe file stream.

Definition at line 22 of file LogStream.cpp.

~LogStream ( )

Destructor.

Frees all allocated memory. The file stream is not destroyed. All unflushed streams are flushed

Definition at line 73 of file LogStream.cpp.

Member Function Documentation

void addStringForwarder ( LogStringForwarder forwarder)

Appends a string forwarder to the forwarder list.

The forwarder is linked to the string buffer and its message() method is called. If the pointer is NULL or already exists in the forwarder list, nothing is done.

Parameters
forwarderThe forwarder to append.
See also
removeStringForwarder

Definition at line 351 of file LogStream.cpp.

void flush ( )

Flushes the stream contents.

Definition at line 130 of file LogStream.cpp.

LogLevel get_filter ( LogDestination  destination) const

Gives the default log level of a specified destination.

Parameters
destinationThe destination.
Returns
Returns the default log level of the specified destination.
See also
LogLevelFilter

Definition at line 222 of file LogStream.cpp.

bool getFilterRankZero ( LogDestination  dest) const

Checks whether the filter for rank 0 is set on the specified destination.

Parameters
destThe destination to check
Returns
Returns true if the filter is set; otherwise, returns false.

Definition at line 291 of file LogStream.cpp.

LogLevelFilter & getLevelFilter ( LogDestination  dest) const
private

Gives the level filter of a destination.

Parameters
destThe destination
Returns
Returns the level filter

Definition at line 327 of file LogStream.cpp.

std::string getStamp ( LogDestination  destination)

Gives the stamp format of a specified destination.

Parameters
destinationThe destination
Returns
Returns the stamp format of the specified destination
See also
LogStampFilter

Definition at line 257 of file LogStream.cpp.

LogStampFilter & getStampFilter ( LogDestination  dest) const
private

Gives the stamp filter of a destination.

Parameters
destThe destination
Returns
Returns the stamp filter

Definition at line 335 of file LogStream.cpp.

unsigned int getStringForwarderCount ( ) const

Gives the number of string forwarders the stream contains.

Returns
Returns the number of string forwarders.

Definition at line 371 of file LogStream.cpp.

bool isDestinationUsed ( LogDestination  destination) const

Gives the use policy of a destination.

If destination is FILE but isFileOpen() returns false, this method returns false.

Returns
The use policy of the specified destination.

Definition at line 238 of file LogStream.cpp.

bool isFileOpen ( ) const

Cheks whether the file is set.

Returns
Returns true if the file has already been set.

Definition at line 343 of file LogStream.cpp.

LogStream & operator<< ( LogLevel  level)

Overrides operator << for LogLevel type.

Sets #level as current level for all destinations.

Parameters
levelThe level.
Returns
Returns a reference to this object.

Definition at line 87 of file LogStream.cpp.

LogStream & operator<< ( LogTag  tag)

Overrides operator << for #Logtag type.

If tag is ENDLINE, all stream buffers are flushed.

Parameters
tagThe tag
Returns
Returns a reference to this object.

Definition at line 103 of file LogStream.cpp.

LogStream & operator<< ( const CodeLocation codeLoction)

Overrides operator << for LogLevel type.

Sets #codeLoction as current code location for all destinations.

Returns
Returns a reference to this object.

Definition at line 114 of file LogStream.cpp.

LogStream& operator<< ( const T &  t)
inline

Overrides operator << for any type.

Appends t to the stream

Parameters
tThe value to append
Returns
Returns a reference to this object.

Definition at line 104 of file LogStream.hpp.

void removeStringForwarder ( LogStringForwarder forwarder)

Removes a string from the forwarder list.

If the pointer is NULL or does not exist in the forwarder list, nothing is done.

Warning
A string forwarder should be always removed from all streams it has been appended to before it is destroyed. Not doing so might result to a segmentation fault.
Parameters
forwarderThe forwarder to remove.
See also
addStringForwarder

Definition at line 363 of file LogStream.cpp.

void set_filter ( LogLevel  level)

Sets new default level.

level is set as default log level to all destinations.

Parameters
levelThe new default level.
See also
LogLevelFilter

Definition at line 199 of file LogStream.cpp.

void set_filter ( LogDestination  destination,
LogLevel  level 
)

Sets new default level to the specified destination.

If destination is FILE but isFileOpen() returns false, nothing is done.

Parameters
destinationThe destination.
levelThe new default level.
See also
LogLevelFilter

Definition at line 214 of file LogStream.cpp.

void set_log_level ( const Uint  level)

Sets new default level.

level is set as default log level to all destinations.

Parameters
levelThe new default level.
See also
LogLevelFilter

Definition at line 177 of file LogStream.cpp.

void set_log_level ( LogDestination  destination,
const Uint  level 
)

Sets new default level to the specified destination.

If destination is FILE but isFileOpen() returns false, nothing is done.

Parameters
destinationThe destination.
levelThe new default level.
See also
LogLevelFilter

Definition at line 191 of file LogStream.cpp.

void setFile ( const boost::iostreams::file_descriptor_sink &  fileDescr)

Sets the file.

Once this method has been called:

  • it cannot be called another time and, if so, will exit immediately.
  • FILE destination becomes available and isFileOpen() returns true.
    Parameters
    fileDescrThe file descriptor.

Definition at line 310 of file LogStream.cpp.

void setFilterRankZero ( LogDestination  dest,
bool  filterRankZero 
)

Enables or disables the filter on MPI rank zero on a destination.

If enabled, only messages coming from process with MPI rank zero are forwarded to that destination.

Parameters
destThe destination
filterRankZeroIf true, the filter is set to "enabled"; otherwise, it is set to "disabled".

Definition at line 283 of file LogStream.cpp.

void setFilterRankZero ( bool  filterRankZero)

Enables or disables the filter on MPI rank zero on all destinations.

If enabled, only messages coming from process with MPI rank zero are forwarded to that destination.

Parameters
filterRankZeroIf true, the filter is set to "enabled"; otherwise, it is set to "disabled".

Definition at line 299 of file LogStream.cpp.

void setStamp ( LogDestination  destination,
const std::string &  stampFormat 
)

Sets a stamp format to a specified destination.

If destination is FILE but isFileOpen() returns false, nothing is done.

Parameters
destinationThe destination
stampFormatThe stamp format
See also
LogStampFilter

Definition at line 249 of file LogStream.cpp.

void setStamp ( const std::string &  stampFormat)

Sets a stamp format to all destinations.

Parameters
stampFormatThe stamp format
See also
LogStampFilter

Definition at line 269 of file LogStream.cpp.

void useDestination ( LogDestination  destination,
bool  use 
)

Modifies the use policy of a destination.

If destination is FILE but isFileOpen() returns false, nothing is done.

Parameters
destinationThe destination.
useIf true, the destination is set to "use"; otherwise it is set to "not use".

Definition at line 230 of file LogStream.cpp.

Member Data Documentation

std::string m_buffer
private

Buffer for STRING destination.

Definition at line 303 of file LogStream.hpp.

std::map<LogDestination, boost::iostreams::filtering_ostream *> m_destinations
private

Destinations.

The key is the destination. The value is the corresponding stream.

Definition at line 287 of file LogStream.hpp.

LogLevel m_filter_level
private

Default value.

This attribute is used on FILE stream creation. Its value is modified by #setLogLevel(LogLevel).

Definition at line 314 of file LogStream.hpp.

std::map<LogDestination, bool> m_filterRankZero
private

Rank zero filter.

The key is the destination. The value is the corresponding filter policy.

Definition at line 300 of file LogStream.hpp.

bool m_flushed
private

Flush status.

If true, the streams are flushed. This attribute is used in object destrutor. If at this moment, it is false, the streams are flushed before their destruction.

Definition at line 321 of file LogStream.hpp.

std::string m_streamName
private

Stream name.

This attribute is used on FILE stream creation.

Definition at line 308 of file LogStream.hpp.

std::list<LogStringForwarder *> m_stringForwarders
private

The forwarder list.

Definition at line 290 of file LogStream.hpp.

std::map<LogDestination, bool> m_usedDests
private

Use policies.

The key is the destination. The value is the corresponding use policy.

Definition at line 295 of file LogStream.hpp.


The documentation for this class was generated from the following files:
Send comments to:
COOLFluiD Web Admin