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// SPHINX_SLIC_INCLUDES_BEGIN
 2// Slic includes
 3#include "axom/slic.hpp"
 4// SPHINX_SLIC_INCLUDES_END
 5
 6using namespace axom;
 7
 8//------------------------------------------------------------------------------
 9int main(int AXOM_UNUSED_PARAM(argc), char** AXOM_UNUSED_PARAM(argv))
10{
11  // SPHINX_SLIC_INIT_BEGIN
12
13  slic::initialize();
14
15  // SPHINX_SLIC_INIT_END
16
17  slic::disableAbortOnError();
18
19  // SPHINX_SLIC_FORMAT_MSG_BEGIN
20
21  std::string format = std::string("<TIMESTAMP>\n") +
22    std::string("[ <LEVEL> <TAG>]: <MESSAGE> \n") +
23    std::string("FILE=<FILE>\n") + std::string("LINE=<LINE>\n\n");
24
25  // SPHINX_SLIC_FORMAT_MSG_END
26
27  // SPHINX_SLIC_SET_SEVERITY_BEGIN
28
29  slic::setLoggingMsgLevel(slic::message::Debug);
30
31  // SPHINX_SLIC_SET_SEVERITY_END
32
33  // SPHINX_SLIC_SET_STREAM_BEGIN
34  slic::addStreamToAllMsgLevels(new slic::GenericOutputStream(&std::cout, format));
35
36  // SPHINX_SLIC_SET_STREAM_END
37
38  // SPHINX_SLIC_SET_TAGGED_STREAM_BEGIN
39  slic::addStreamToTag(new slic::GenericOutputStream(&std::cout, format),
40                       "myTag");
41
42  // SPHINX_SLIC_SET_TAGGED_STREAM_END
43
44  // SPHINX_SLIC_LOG_MESSAGES_BEGIN
45
46  SLIC_DEBUG("Here is a debug message!");
47  SLIC_INFO("Here is an info mesage!");
48  SLIC_WARNING("Here is a warning!");
49  SLIC_ERROR("Here is an error message!");
50  SLIC_INFO_TAGGED("Here is a message for tagged streams with tag 'myTag'!",
51                   "myTag");
52
53  // SPHINX_SLIC_LOG_MESSAGES_END
54
55  // SPHINX_SLIC_FINALIZE_BEGIN
56
57  slic::finalize();
58
59  // SPHINX_SLIC_FINALIZE_END
60
61  return 0;
62}

axom::utilities::processAbort()

The axom::utilities::processAbort() function gracefully aborts the application by:

  1. Calling abort() if it is a serial application.

  2. 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
SLIC_INFO_TAGGED
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