AXOM
Axom provides a robust, flexible software infrastructure for the development of multi-physics applications and computational tools.
axom::slic::LumberjackStream Class Reference

A concrete instance of LogStream that utilizes Lumberjack to filter and pass messages between MPI nodes. More...

#include </home/docs/checkouts/readthedocs.org/user_builds/axom/checkouts/main/src/axom/slic/streams/LumberjackStream.hpp>

Inheritance diagram for axom::slic::LumberjackStream:

Public Member Functions

 LumberjackStream (std::ostream *stream, MPI_Comm comm, int ranksLimit)
 Constructs a LumberjackStream instance with the given stream, MPI communicator, and rank limit. More...
 
 LumberjackStream (std::ostream *stream, MPI_Comm comm, int ranksLimit, const std::string &format)
 Constructs a LumberjackStream instance with the given stream, MPI communicator, rank limit, and message formatting. More...
 
 LumberjackStream (std::ostream *stream, axom::lumberjack::Lumberjack *lj)
 Constructs a LumberjackStream instance with the given stream and Lumberjack communicator. More...
 
 LumberjackStream (std::ostream *stream, axom::lumberjack::Lumberjack *lj, const std::string &format)
 Constructs a LumberjackStream instance with the given stream Lumberjack communicator, and message formatting. More...
 
 LumberjackStream (std::string stream, MPI_Comm comm, int ranksLimit)
 Constructs a LumberjackStream instance specified by the given string, MPI communicator, and rank limit. The string input determines the stream as follows: More...
 
 LumberjackStream (std::string stream, MPI_Comm comm, int ranksLimit, const std::string &format)
 Constructs a LumberjackStream instance specified by the given string, MPI communicator, rank limit, and message formatting. The string input determines the stream as follows: More...
 
 LumberjackStream (std::string stream, axom::lumberjack::Lumberjack *lj)
 Constructs a LumberjackStream instance specified by the given string and Lumberjack communicator. The string input determines the stream as follows: More...
 
 LumberjackStream (std::string stream, axom::lumberjack::Lumberjack *lj, const std::string &format)
 Constructs a LumberjackStream instance specified by the given string, Lumberjack communicator, and message formatting. The string input determines the stream as follows: More...
 
virtual ~LumberjackStream ()
 
virtual void append (message::Level msgLevel, const std::string &message, const std::string &tagName, const std::string &fileName, int line, bool filter_duplicates, bool tag_stream_only) override
 Appends the given message to the stream. More...
 
virtual void outputLocal () override
 Pushes the messages from the current rank directly to the console (non-collectively). More...
 
virtual void flush () override
 Pushes all messages to the output node according to Lumberjack's Communication scheme. Then writes it to the console. More...
 
virtual void push () override
 Pushes all messages once to their parent node according to Lumberjack's Communication scheme. More...
 
void write (bool local=false)
 Writes the messages to the given stream that are at the output node or at the current node if local is true. More...
 
virtual bool hasPendingMessages () override
 Tests whether there are any pending messages that need to be flushed. More...
 
virtual bool isUsingMPI () override
 Tests whether this class relies on MPI. More...
 
virtual MPI_Comm comm () override
 Get the communicator. More...
 
void setFormatString (const std::string &format)
 Sets the format string. More...
 

Protected Member Functions

void initializeLumberjack (MPI_Comm comm, int ranksLimit)
 
void finalizeLumberjack ()
 
std::string getFormatedMessage (const std::string &msgLevel, const std::string &message, const std::string &tagName, const std::string &rank, const std::string &rank_count, const std::string &fileName, int line)
 Get the communicator. More...
 
std::string getTimeStamp ()
 Returns a time-stamp. More...
 

Protected Attributes

Protected Members
axom::lumberjack::Lumberjackm_lj
 
axom::lumberjack::Communicatorm_ljComm
 
bool m_isLJOwnedBySLIC
 
bool m_isOstreamOwnedBySLIC
 
std::ostream * m_stream
 
std::string m_file_name
 
bool m_opened
 

Detailed Description

A concrete instance of LogStream that utilizes Lumberjack to filter and pass messages between MPI nodes.

Constructor & Destructor Documentation

◆ LumberjackStream() [1/8]

axom::slic::LumberjackStream::LumberjackStream ( std::ostream *  stream,
MPI_Comm  comm,
int  ranksLimit 
)

Constructs a LumberjackStream instance with the given stream, MPI communicator, and rank limit.

Parameters
[in]streampointer to a user-supplied ostream instance.
[in]commMPI communicator
[in]ranksLimitlimit on how many ranks are individually tracked per message
Precondition
stream != NULL

◆ LumberjackStream() [2/8]

axom::slic::LumberjackStream::LumberjackStream ( std::ostream *  stream,
MPI_Comm  comm,
int  ranksLimit,
const std::string &  format 
)

Constructs a LumberjackStream instance with the given stream, MPI communicator, rank limit, and message formatting.

Parameters
[in]streampointer to a user-supplied ostream instance.
[in]commMPI communicator
[in]ranksLimitlimit on how many ranks are individually tracked per message
[in]formatthe format string.
Precondition
stream != NULL
See also
LogStream::setFormatString for the format string.

◆ LumberjackStream() [3/8]

axom::slic::LumberjackStream::LumberjackStream ( std::ostream *  stream,
axom::lumberjack::Lumberjack lj 
)

Constructs a LumberjackStream instance with the given stream and Lumberjack communicator.

Parameters
[in]streampointer to a user-supplied ostream instance.
[in]ljLumberjack communicator
Precondition
stream != NULL

◆ LumberjackStream() [4/8]

axom::slic::LumberjackStream::LumberjackStream ( std::ostream *  stream,
axom::lumberjack::Lumberjack lj,
const std::string &  format 
)

Constructs a LumberjackStream instance with the given stream Lumberjack communicator, and message formatting.

Parameters
[in]streampointer to a user-supplied ostream instance.
[in]ljLumberjack communicator
[in]formatthe format string.
Precondition
stream != NULL

◆ LumberjackStream() [5/8]

axom::slic::LumberjackStream::LumberjackStream ( std::string  stream,
MPI_Comm  comm,
int  ranksLimit 
)

Constructs a LumberjackStream instance specified by the given string, MPI communicator, and rank limit. The string input determines the stream as follows:

  • "cout" makes std::cout the output stream
  • "cerr" makes std::cerr the output stream
  • Any other input will construct a std::ofstream associated with input
    Parameters
    [in]streamthe string to control type of stream created
    [in]commMPI communicator
    [in]ranksLimitlimit on how many ranks are individually tracked per message
    Precondition
    stream != NULL
    Note
    This constructor avoids creating an empty file if this LumberjackStream never flushes a message.

◆ LumberjackStream() [6/8]

axom::slic::LumberjackStream::LumberjackStream ( std::string  stream,
MPI_Comm  comm,
int  ranksLimit,
const std::string &  format 
)

Constructs a LumberjackStream instance specified by the given string, MPI communicator, rank limit, and message formatting. The string input determines the stream as follows:

  • "cout" makes std::cout the output stream
  • "cerr" makes std::cerr the output stream
  • Any other input will construct a std::ofstream associated with input
    Parameters
    [in]streamthe string to control type of stream created
    [in]commMPI communicator
    [in]ranksLimitlimit on how many ranks are individually tracked per message
    [in]formatthe format string.
    Precondition
    stream != NULL
    See also
    LogStream::setFormatString for the format string.
    Note
    This constructor avoids creating an empty file if this LumberjackStream never flushes a message.

◆ LumberjackStream() [7/8]

axom::slic::LumberjackStream::LumberjackStream ( std::string  stream,
axom::lumberjack::Lumberjack lj 
)

Constructs a LumberjackStream instance specified by the given string and Lumberjack communicator. The string input determines the stream as follows:

  • "cout" makes std::cout the output stream
  • "cerr" makes std::cerr the output stream
  • Any other input will construct a std::ofstream associated with input
    Parameters
    [in]streamthe string to control type of stream created
    [in]ljLumberjack communicator
    Precondition
    stream != NULL
    Note
    This constructor avoids creating an empty file if this LumberjackStream never flushes a message.

◆ LumberjackStream() [8/8]

axom::slic::LumberjackStream::LumberjackStream ( std::string  stream,
axom::lumberjack::Lumberjack lj,
const std::string &  format 
)

Constructs a LumberjackStream instance specified by the given string, Lumberjack communicator, and message formatting. The string input determines the stream as follows:

  • "cout" makes std::cout the output stream
  • "cerr" makes std::cerr the output stream
  • Any other input will construct a std::ofstream associated with input
    Parameters
    [in]streamthe string to control type of stream created
    [in]ljLumberjack communicator
    [in]formatthe format string.
    Precondition
    stream != NULL
    See also
    LogStream::setFormatString for the format string.
    Note
    This constructor avoids creating an empty file if this LumberjackStream never flushes a message.

◆ ~LumberjackStream()

virtual axom::slic::LumberjackStream::~LumberjackStream ( )
virtual

Member Function Documentation

◆ append()

virtual void axom::slic::LumberjackStream::append ( message::Level  msgLevel,
const std::string &  message,
const std::string &  tagName,
const std::string &  fileName,
int  line,
bool  filter_duplicates,
bool  tag_stream_only 
)
overridevirtual

Appends the given message to the stream.

Parameters
[in]msgLevelthe level of the message.
[in]messagethe user-supplied message.
[in]tagNameuser-supplied tag to associate with the given message.
[in]fileNamethe file where this message is appended
[in]linethe line within the file at which the message is appended.
[in]filter_duplicatesoptional parameter that indicates whether duplicate messages resulting from running in parallel will be filtered out. /param [in] tag_stream_only optional parameter that indicates whether the message will go only to streams bound to tagName.
Note
This method doesn't put anything to the console. Instead the messages are cached locally to each ranks and are dumped to the console in rank order when flush is called.

Implements axom::slic::LogStream.

◆ outputLocal()

virtual void axom::slic::LumberjackStream::outputLocal ( )
overridevirtual

Pushes the messages from the current rank directly to the console (non-collectively).

Warning
This method is being called before slic aborts.

Reimplemented from axom::slic::LogStream.

◆ flush()

virtual void axom::slic::LumberjackStream::flush ( )
overridevirtual

Pushes all messages to the output node according to Lumberjack's Communication scheme. Then writes it to the console.

Note
This method is a collective operation intended for a synchronization checkpoint.

Reimplemented from axom::slic::LogStream.

◆ push()

virtual void axom::slic::LumberjackStream::push ( )
overridevirtual

Pushes all messages once to their parent node according to Lumberjack's Communication scheme.

Note
This method is a collective operation intended for a synchronization checkpoint.
This does not guarantee all messages have reached the output node.
This does not write out to the given stream.

Reimplemented from axom::slic::LogStream.

◆ write()

void axom::slic::LumberjackStream::write ( bool  local = false)

Writes the messages to the given stream that are at the output node or at the current node if local is true.

param [in] local If true, writes out messages at the current node. If false, only writes out messages at the output node. Default is false.

It does not flush any messages and not all messages are guaranteed to be at the output node.

◆ hasPendingMessages()

virtual bool axom::slic::LumberjackStream::hasPendingMessages ( )
overridevirtual

Tests whether there are any pending messages that need to be flushed.

Returns
Returns true if there are pending messages that need to be flushed

Reimplemented from axom::slic::LogStream.

◆ isUsingMPI()

virtual bool axom::slic::LumberjackStream::isUsingMPI ( )
overridevirtual

Tests whether this class relies on MPI.

Returns
Returns true if this class relies on MPI

Reimplemented from axom::slic::LogStream.

◆ comm()

virtual MPI_Comm axom::slic::LumberjackStream::comm ( )
overridevirtual

Get the communicator.

Returns
Returns the communicator if it exists, or MPI_COMM_NULL otherwise

◆ initializeLumberjack()

void axom::slic::LumberjackStream::initializeLumberjack ( MPI_Comm  comm,
int  ranksLimit 
)
protected

◆ finalizeLumberjack()

void axom::slic::LumberjackStream::finalizeLumberjack ( )
protected

◆ setFormatString()

void axom::slic::LogStream::setFormatString ( const std::string &  format)
inlineinherited

Sets the format string.

Parameters
formata format string
Note
The following keywords in the format string are replaced:
  • <LEVEL> with the message type, e.g, ERROR, FATAL, etc.
  • <MESSAGE> with the user-supplied message
  • <TAG> user-supplied tag
  • <FILE> with the filename
  • <LINE> with the line number
  • <RANK> with the MPI rank(s)
  • <RANK_COUNT> with the number of MPI ranks
  • <TIMESTAMP> date/time the message is logged

An example illustrating how an application can setup the format string is shown below:

std::string format =
std::string( "***********************************\n" )+
std::string( "* <TIMESTAMP>\n\n" ) +
std::string( "* LEVEL=<LEVEL>\n" ) +
std::string( "* MESSAGE=<MESSAGE>\n" ) +
std::string( "* FILE=<FILE>\n" ) +
std::string( "* LINE=<LINE>\n" ) +
std::string( "* RANK=<RANK>\n" ) +
std::string( "* RANK_COUNT=<RANK_COUNT>\n" ) +
std::string( "***********************************\n" );

◆ getFormatedMessage()

std::string axom::slic::LogStream::getFormatedMessage ( const std::string &  msgLevel,
const std::string &  message,
const std::string &  tagName,
const std::string &  rank,
const std::string &  rank_count,
const std::string &  fileName,
int  line 
)
protectedinherited

Get the communicator.

Returns
Returns the communicator if it exists, or MPI_COMM_NULL otherwise

Returns the formatted message as a single string.

Parameters
[in]msgLevelthe level of the given message.
[in]messagethe user-supplied message.
[in]tagNameuser-supplied tag, may be MSG_IGNORE_TAG
[in]fileNamefilename where this message is logged, may be MSG_IGNORE_FILE to ignore this field.
[in]rankThe MPI rank(s) that emitted this message
[in]rank_countthe number of MPI ranks that emitted this message
[in]linethe line number within the file where the message is logged. Likewise, may be set to MSG_IGNORE_LINE to ignore this field.
Returns
str the formatted message string.
Postcondition
str != "".

◆ getTimeStamp()

std::string axom::slic::LogStream::getTimeStamp ( )
protectedinherited

Returns a time-stamp.

Returns
str a textual representation of the current time.

Member Data Documentation

◆ m_lj

axom::lumberjack::Lumberjack* axom::slic::LumberjackStream::m_lj
protected

◆ m_ljComm

axom::lumberjack::Communicator* axom::slic::LumberjackStream::m_ljComm
protected

◆ m_isLJOwnedBySLIC

bool axom::slic::LumberjackStream::m_isLJOwnedBySLIC
protected

◆ m_isOstreamOwnedBySLIC

bool axom::slic::LumberjackStream::m_isOstreamOwnedBySLIC
protected

◆ m_stream

std::ostream* axom::slic::LumberjackStream::m_stream
protected

◆ m_file_name

std::string axom::slic::LumberjackStream::m_file_name
protected

◆ m_opened

bool axom::slic::LumberjackStream::m_opened
protected

The documentation for this class was generated from the following file: