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

A singleton class for logging error, debug and warning messages. More...

#include </home/docs/checkouts/readthedocs.org/user_builds/axom/checkouts/latest/src/axom/slic/core/Logger.hpp>

Public Member Functions

message::Level getLoggingMsgLevel ()
 Gets the currently set logging level. More...
 
void setLoggingMsgLevel (message::Level level)
 Sets the logging level to the given level. This controls which messages are logged based on severity. All messages with equal or higher severity to the given level will be logged. More...
 
void setAbortOnError (bool status)
 Toggles the abort behavior for error messages. Default is true. More...
 
void enableAbortOnError ()
 Enables abort on error messages. More...
 
void disableAbortOnError ()
 Disables abort on error messages. More...
 
bool isAbortOnErrorsEnabled () const
 Checks the status of the abort behavior on error messages. More...
 
void setAbortOnWarning (bool status)
 Toggles the abort behavior for warning messages. Default is false. More...
 
void enableAbortOnWarning ()
 Enables abort on warning messages. More...
 
void disableAbortOnWarning ()
 Disables abort on warnings messages. More...
 
bool isAbortOnWarningsEnabled () const
 Checks the status of the abort behavior on warning messages. More...
 
void setAbortFunction (AbortFunctionPtr abort_func)
 Sets the function to call when program abort is requested. More...
 
std::string getName () const
 Returns the name of this logger instance. More...
 
void addStreamToMsgLevel (LogStream *ls, message::Level level, bool pass_ownership=true)
 Binds the given stream to the given level for this Logger instance. More...
 
void addStreamToAllMsgLevels (LogStream *ls, bool pass_ownership=true)
 Binds the given stream to all the levels for this Logger instance. More...
 
int getNumStreamsAtMsgLevel (message::Level level)
 Returns the number of streams at the given level. More...
 
LogStreamgetStream (message::Level level, int i)
 Returns the ith stream at the given level. More...
 
void addStreamToTag (LogStream *ls, const std::string &tag, bool pass_ownership=true)
 Binds the given stream to the given tag for this Logger instance. More...
 
void addStreamToAllTags (LogStream *ls, bool pass_ownership=true)
 Binds the given stream to all the tags for this Logger instance. More...
 
int getNumStreamsWithTag (const std::string &tag)
 Returns the number of streams for a given tag. Returns 0 if the tag does not exist. More...
 
LogStreamgetStream (const std::string &tag, int i)
 Returns the ith stream at the given tag. More...
 
void logMessage (message::Level level, const std::string &message, bool filter_duplicates=false)
 Logs the given message to all registered streams. More...
 
void logMessage (message::Level level, const std::string &message, const std::string &tagName, bool filter_duplicates=false, bool tag_stream_only=false)
 Logs the given message to all registered streams. More...
 
void logMessage (message::Level level, const std::string &message, const std::string &fileName, int line, bool filter_duplicates=false)
 Logs the given message to all registered streams. More...
 
void logMessage (message::Level level, const std::string &message, const std::string &tagName, const std::string &fileName, int line, bool filter_duplicates=false, bool tag_stream_only=false)
 Logs the given message to all registered streams. More...
 
void outputLocalMessages ()
 For the current rank, outputs messages from all streams to the console. More...
 
Collective Methods
Attention
These methods are collective operations. All ranks in the user-supplied communicator must call the method when used within an MPI distributed environment.
void abort ()
 Calls abort function. Default is abort() or MPI_Abort() in a MPI distributed environment. More...
 
void flushStreams ()
 Flushes all streams for all ranks. More...
 
void pushStreams ()
 Pushes messages incrementally up all streams. More...
 

Static Public Member Functions

Static Methods
static void initialize ()
 Initializes the logging environment, with the root logger. More...
 
static bool createLogger (const std::string &name, char imask=inherit::nothing)
 Creates a new logger associated with the given name. More...
 
static bool activateLogger (const std::string &name)
 Activates the logger with the associate name. More...
 
static void finalize ()
 Finalizes the logging environment. More...
 
static std::string getActiveLoggerName ()
 Returns the name of the currently active logger instance. More...
 
static LoggergetActiveLogger ()
 Returns a pointer to the logger instance. More...
 
static LoggergetRootLogger ()
 Returns the root logger. More...
 

Detailed Description

A singleton class for logging error, debug and warning messages.

Applications using this logging facility must call initialize() and finalize(), typically in the beginning and end of the application's main() respectively. Logging messages can then be accomplished through calls to 'logMessage(type,msg,file,line)' or through the convenience macro layer, which allows for logging messages to be compiled out.

The Logger appends the messages to the set of registered LogStreams. Messages are logged using the LogStream abstraction layer. This allows an application to use some of the predefined LogStream mechanisms or implement a custom one by implementing a derivative of the LogStream class.

See also
LogStream MessageType

Member Function Documentation

◆ getLoggingMsgLevel()

message::Level axom::slic::Logger::getLoggingMsgLevel ( )

Gets the currently set logging level.

Returns
The currently set logging level.

◆ setLoggingMsgLevel()

void axom::slic::Logger::setLoggingMsgLevel ( message::Level  level)

Sets the logging level to the given level. This controls which messages are logged based on severity. All messages with equal or higher severity to the given level will be logged.

Parameters
[in]levelthe logging level.

◆ setAbortOnError()

void axom::slic::Logger::setAbortOnError ( bool  status)
inline

Toggles the abort behavior for error messages. Default is true.

Parameters
[in]statususer-supplied flag.

◆ enableAbortOnError()

void axom::slic::Logger::enableAbortOnError ( )
inline

Enables abort on error messages.

Postcondition
this->isAbortOnErrorsEnabled() == true.

◆ disableAbortOnError()

void axom::slic::Logger::disableAbortOnError ( )
inline

Disables abort on error messages.

Postcondition
this->isAbortOnErrorsEnabled() == false.

◆ isAbortOnErrorsEnabled()

bool axom::slic::Logger::isAbortOnErrorsEnabled ( ) const
inline

Checks the status of the abort behavior on error messages.

Returns
status true if the code will abort on errors, otherwise, false.

◆ setAbortOnWarning()

void axom::slic::Logger::setAbortOnWarning ( bool  status)
inline

Toggles the abort behavior for warning messages. Default is false.

Parameters
[in]statususer-supplied flag.

◆ enableAbortOnWarning()

void axom::slic::Logger::enableAbortOnWarning ( )
inline

Enables abort on warning messages.

Postcondition
this->isAbortOnWarningsEnabled() == true.

◆ disableAbortOnWarning()

void axom::slic::Logger::disableAbortOnWarning ( )
inline

Disables abort on warnings messages.

Postcondition
this->isAbortOnWarningsEnabled() == false.

◆ isAbortOnWarningsEnabled()

bool axom::slic::Logger::isAbortOnWarningsEnabled ( ) const
inline

Checks the status of the abort behavior on warning messages.

Returns
status true if the code will abort on warnings, otherwise, false.

◆ setAbortFunction()

void axom::slic::Logger::setAbortFunction ( AbortFunctionPtr  abort_func)

Sets the function to call when program abort is requested.

Parameters
[in]abort_funcThe user-specified function to call
Warning
No collective calls should be made in the given function. Collective calls may cause the program to hang on abort.

◆ getName()

std::string axom::slic::Logger::getName ( ) const
inline

Returns the name of this logger instance.

Returns
s a string corresponding to the name of this logger instance.
Postcondition
s.length() > 0

◆ addStreamToMsgLevel()

void axom::slic::Logger::addStreamToMsgLevel ( LogStream ls,
message::Level  level,
bool  pass_ownership = true 
)

Binds the given stream to the given level for this Logger instance.

Parameters
[in]lspointer to the user-supplied LogStream object.
[in]levelthe level that this stream will be associated with.
[in]pass_ownershipflag that indicates whether the given logger instance owns the supplied LogStream object. This parameter is optional. Default is true.
Note
The Logger takes ownership of the LogStream object.
Precondition
ls != NULL.

◆ addStreamToAllMsgLevels()

void axom::slic::Logger::addStreamToAllMsgLevels ( LogStream ls,
bool  pass_ownership = true 
)

Binds the given stream to all the levels for this Logger instance.

Parameters
[in]lspointer to the user-supplied LogStream object.
[in]pass_ownershipflag that indicates whether the given logger instance owns the supplied LogStream object. This parameter is optional. Default is true.
Note
The Logger takes ownership of the LogStream object.
Precondition
ls != NULL.

◆ getNumStreamsAtMsgLevel()

int axom::slic::Logger::getNumStreamsAtMsgLevel ( message::Level  level)

Returns the number of streams at the given level.

Parameters
[in]levelthe level in query.
Returns
N the number of streams at the given level.
Postcondition
N >= 0

◆ getStream() [1/2]

LogStream* axom::slic::Logger::getStream ( message::Level  level,
int  i 
)

Returns the ith stream at the given level.

Parameters
[in]levelthe level in query.
[in]ithe index of the stream in query.
Returns
stream_ptr pointer to the stream.
Precondition
i >= 0 && i < this->getNumStreamsAtLevel( level )
Postcondition
stream_ptr != NULL.

◆ addStreamToTag()

void axom::slic::Logger::addStreamToTag ( LogStream ls,
const std::string &  tag,
bool  pass_ownership = true 
)

Binds the given stream to the given tag for this Logger instance.

Parameters
[in]lspointer to the user-supplied LogStream object.
[in]tagthe tag that this stream will be associated with.
[in]pass_ownershipflag that indicates whether the given logger instance owns the supplied LogStream object. This parameter is optional. Default is true.
Note
The Logger takes ownership of the LogStream object.
Precondition
ls != NULL.

◆ addStreamToAllTags()

void axom::slic::Logger::addStreamToAllTags ( LogStream ls,
bool  pass_ownership = true 
)

Binds the given stream to all the tags for this Logger instance.

Parameters
[in]lspointer to the user-supplied LogStream object.
[in]pass_ownershipflag that indicates whether the given logger instance owns the supplied LogStream object. This parameter is optional. Default is true.
Note
The Logger takes ownership of the LogStream object.
Precondition
ls != NULL.

◆ getNumStreamsWithTag()

int axom::slic::Logger::getNumStreamsWithTag ( const std::string &  tag)

Returns the number of streams for a given tag. Returns 0 if the tag does not exist.

Parameters
[in]tagthe tag in query.
Returns
N the number of streams for the given tag.
Postcondition
N >= 0

◆ getStream() [2/2]

LogStream* axom::slic::Logger::getStream ( const std::string &  tag,
int  i 
)

Returns the ith stream at the given tag.

Parameters
[in]tagthe tag in query.
[in]ithe index of the stream in query.
Returns
stream_ptr pointer to the stream.
Precondition
i >= 0 && i < this->getNumStreamsWithTag( tag )
Postcondition
stream_ptr != NULL.

◆ logMessage() [1/4]

void axom::slic::Logger::logMessage ( message::Level  level,
const std::string &  message,
bool  filter_duplicates = false 
)

Logs the given message to all registered streams.

Parameters
[in]levelthe level of the given message.
[in]messagethe user-supplied message to log.
[in]filter_duplicatesoptional parameter that indicates whether duplicate messages resulting from running in parallel will be filtered out. Default is false.

◆ logMessage() [2/4]

void axom::slic::Logger::logMessage ( message::Level  level,
const std::string &  message,
const std::string &  tagName,
bool  filter_duplicates = false,
bool  tag_stream_only = false 
)

Logs the given message to all registered streams.

Parameters
[in]levelthe level of the given message.
[in]messagethe user-supplied message to log.
[in]tagNameuser-supplied tag to associated with the given message.
[in]filter_duplicatesoptional parameter that indicates whether duplicate messages resulting from running in parallel will be filtered out. Default is false. /param [in] tag_stream_only optional parameter that indicates whether the message will go only to streams bound to tagName. Default is false.

◆ logMessage() [3/4]

void axom::slic::Logger::logMessage ( message::Level  level,
const std::string &  message,
const std::string &  fileName,
int  line,
bool  filter_duplicates = false 
)

Logs the given message to all registered streams.

Parameters
[in]levelthe level of the given message.
[in]messagethe user-supplied message to log.
[in]fileNamename of the file this call is made from.
[in]lineline within the file that this call is made from.
[in]filter_duplicatesoptional parameter that indicates whether duplicate messages resulting from running in parallel will be filtered out. Default is false.

◆ logMessage() [4/4]

void axom::slic::Logger::logMessage ( message::Level  level,
const std::string &  message,
const std::string &  tagName,
const std::string &  fileName,
int  line,
bool  filter_duplicates = false,
bool  tag_stream_only = false 
)

Logs the given message to all registered streams.

Parameters
[in]levelthe level of the given message.
[in]messagethe user-supplied message to log.
[in]tagNameuser-supplied tag to associated with the given message.
[in]fileNamename of the file this call is made from.
[in]lineline within the file that this call is made from.
[in]filter_duplicatesoptional parameter that indicates whether duplicate messages resulting from running in parallel will be filtered out. Default is false. /param [in] tag_stream_only optional parameter that indicates whether the message will go only to streams bound to tagName. Default is false.

◆ outputLocalMessages()

void axom::slic::Logger::outputLocalMessages ( )

For the current rank, outputs messages from all streams to the console.

Warning
outputLocalMessages() is used before a rank aborts. flushStreams() is preferred over this function, as outputLocalMessages() may put LogStreams in an undesirable state. This call is not collective.

◆ abort()

void axom::slic::Logger::abort ( )

Calls abort function. Default is abort() or MPI_Abort() in a MPI distributed environment.

◆ flushStreams()

void axom::slic::Logger::flushStreams ( )

Flushes all streams for all ranks.

Note
When used within an MPI distributed environment, flushStreams is a collective operation. All ranks in the user-supplied communicator must call this method.

◆ pushStreams()

void axom::slic::Logger::pushStreams ( )

Pushes messages incrementally up all streams.

◆ initialize()

static void axom::slic::Logger::initialize ( )
static

Initializes the logging environment, with the root logger.

Postcondition
Logger::getActiveLogger() != NULL.

◆ createLogger()

static bool axom::slic::Logger::createLogger ( const std::string &  name,
char  imask = inherit::nothing 
)
static

Creates a new logger associated with the given name.

Parameters
[in]namethe name to associate with the new logger.
[in]imaskinheritance mask, indicates the log level(s), which will be inherited from the "root" logger. By default, nothing is inherited.
Returns
status return status, true if the logger is created, else false.
Note
False is returned if a logger associated with the given name already exists.

◆ activateLogger()

static bool axom::slic::Logger::activateLogger ( const std::string &  name)
static

Activates the logger with the associate name.

Parameters
[in]namethe name of the logger to activate.
Returns
status return status, true if the logger is activated, else false.
Note
False is returned if the logger with the given name does not exist.

◆ finalize()

static void axom::slic::Logger::finalize ( )
static

Finalizes the logging environment.

Postcondition
Logger::getActiveLogger() == NULL.
Attention
This method is a collective operation. All ranks in the user-supplied communicator must call the method when used within an MPI distributed environment.

◆ getActiveLoggerName()

static std::string axom::slic::Logger::getActiveLoggerName ( )
static

Returns the name of the currently active logger instance.

Returns
s a string corresponding to the name of the active logger.
Postcondition
s.length() > 0

◆ getActiveLogger()

static Logger* axom::slic::Logger::getActiveLogger ( )
static

Returns a pointer to the logger instance.

Returns
logger pointer to the logger instance.
Precondition
s_Logger != NULL
Postcondition
logger != NULL

◆ getRootLogger()

static Logger* axom::slic::Logger::getRootLogger ( )
static

Returns the root logger.

Returns
logger pointer to the root logger instance.

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