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/v0.5.0/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 false. 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)
 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 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)
 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)
 Logs the given message to all registered streams. More...
 
void flushStreams ()
 Flushes all streams. 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 false.

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.

References setAbortFunction().

◆ 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

Referenced by isAbortOnWarningsEnabled().

◆ getName()

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

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

Referenced by getName().

◆ addStreamToAllMsgLevels()

void axom::slic::Logger::addStreamToAllMsgLevels ( LogStream ls)

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

Parameters
[in]lspointer to the user-supplied LogStream object.
Note
The Logger takes ownership of the LogStream object.
Precondition
ls != NULL.

Referenced by getName().

◆ 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

Referenced by getName().

◆ getStream()

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.

Referenced by getName().

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

Referenced by getName().

◆ logMessage() [2/4]

void axom::slic::Logger::logMessage ( message::Level  level,
const std::string &  message,
const std::string &  tagName,
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]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.

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

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.

◆ flushStreams()

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

Flushes all streams.

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

Referenced by getName().

◆ pushStreams()

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

Pushes messages incrementally up all streams.

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

Referenced by getName().

◆ initialize()

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

Initializes the logging environment, with the root logger.

Postcondition
Logger::getActiveLogger() != NULL.

Referenced by getName().

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

Referenced by getName().

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

Referenced by getName().

◆ finalize()

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

Finalizes the logging environment.

Postcondition
Logger::getActiveLogger() == NULL.

Referenced by getName().

◆ 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

Referenced by getName().

◆ 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

Referenced by getName().

◆ getRootLogger()

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

Returns the root logger.

Returns
logger pointer to the root logger instance.

Referenced by getName().


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