Appendix¶
Slic Application Code Example¶
Below is the complete Slic Application Code Example presented in
the Getting Started with Slic section. The code can be found in the Axom
source code under src/axom/slic/examples/basic/logging.cpp
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 // SPHINX_SLIC_INCLUDES_BEGIN // Slic includes #include "axom/slic.hpp" // SPHINX_SLIC_INCLUDES_END using namespace axom; //------------------------------------------------------------------------------ int main(int AXOM_UNUSED_PARAM(argc), char** AXOM_UNUSED_PARAM(argv)) { // SPHINX_SLIC_INIT_BEGIN slic::initialize(); // SPHINX_SLIC_INIT_END slic::disableAbortOnError(); // SPHINX_SLIC_FORMAT_MSG_BEGIN std::string format = std::string("<TIMESTAMP>\n") + std::string("[<LEVEL>]: <MESSAGE> \n") + std::string("FILE=<FILE>\n") + std::string("LINE=<LINE>\n\n"); // SPHINX_SLIC_FORMAT_MSG_END // SPHINX_SLIC_SET_SEVERITY_BEGIN slic::setLoggingMsgLevel(slic::message::Debug); // SPHINX_SLIC_SET_SEVERITY_END // SPHINX_SLIC_SET_STREAM_BEGIN slic::addStreamToAllMsgLevels(new slic::GenericOutputStream(&std::cout, format)); // SPHINX_SLIC_SET_STREAM_END // SPHINX_SLIC_LOG_MESSAGES_BEGIN SLIC_DEBUG("Here is a debug message!"); SLIC_INFO("Here is an info mesage!"); SLIC_WARNING("Here is a warning!"); SLIC_ERROR("Here is an error message!"); // SPHINX_SLIC_LOG_MESSAGES_END // SPHINX_SLIC_FINALIZE_BEGIN slic::finalize(); // SPHINX_SLIC_FINALIZE_END return 0; }
axom::utilities::processAbort()¶
The axom::utilities::processAbort() function gracefully aborts the application by:
- Calling
abort()
if it is a serial application. - Calls
MPI_Abort()
if the Axom Toolkit is compiled with MPI and the application has initialized MPI, i.e., it’s a distributed MPI application.
Slic Macros Used in Axom¶
Slic provides a set of convenience macros that can be used to streamline logging within an application.
Note
The Slic Macros Used in Axom are not the only interface
to log messages with Slic. They are used within the Axom Toolkit for
convenience. Applications or libraries that adopt Slic, typically, use the
C++ API directly, e.g., call slic::logMessage()
and wrap the
functionality in application specific macros to better suit the requirements
of the application.
Collective Slic Macros¶
A subset of SLIC macros are collective operations when used with MPI-aware Log Stream instances such as Synchronized Stream or Lumberjack Stream.
Additionally, macros such as SLIC_WARNING
and SLIC_CHECK
become collective
operations when certain flags are toggled on or functions are called. Other macros
such as SLIC_ERROR
and SLIC_ASSERT
can be made not collective when certain
functions are called.
The table below details which SLIC macros are collective:
Macro | Collective |
---|---|
SLIC_ASSERT SLIC_ASSERT_MSG |
Collective by default.
Collective after calling
slic::enableAbortOnError() .No longer collective after calling
slic::disableAbortOnError() . |
SLIC_CHECK SLIC_CHECK_MSG |
Not collective by default.
Collective after
slic::debug::checksAreErrors is set to true ,defaults to
false . |
SLIC_DEBUG SLIC_DEBUG_IF SLIC_DEBUG_ROOT SLIC_DEBUG_ROOT_IF |
Never
|
SLIC_INFO SLIC_INFO_IF SLIC_INFO_ROOT SLIC_INFO_ROOT_IF |
Never
|
SLIC_ERROR SLIC_ERROR_IF SLIC_ERROR_ROOT SLIC_ERROR_ROOT_IF |
Collective by default.
Collective after calling
slic::enableAbortOnError() .No longer collective after calling
slic::disableAbortOnError() |
SLIC_WARNING SLIC_WARNING_IF SLIC_WARNING_ROOT SLIC_WARNING_ROOT_IF |
Not collective by default.
Collective after calling
slic::enableAbortOnWarning() .No longer collective after calling
slic::disableAbortOnWarning() |
Doxygen generated API documentation on Macros can be found here: SLIC Macros