Logging and tracing

When developing C++ primitive operators and native functions, use the SPLAPPLOG macro to write messages to the Teracloud® Streams product log location. Use the SPLAPPTRC macro to create a trace in the PE trace files.

The SPLAPPLOG macro

Use the SPLAPPLOG macro to write messages to the Teracloud® Streams product log location.

Write messages to the product log with the Streams administrator in mind. Do not write normal application tracing or application debugging messages. Write product log messages for issues an administrator can fix. Not for issues that require a developer's attention. For example, to include error messages in the log file, use this SPL code:

//        =level=  =message=                         =debug aspects=
SPLAPPLOG(L_ERROR, "Fatal error: missing file" << f, "MY_ASPECT");

The valid identifiers for the level of the SPLAPPLOG macro are L_ERROR, L_WARN(default), and L_INFO. For stand-alone applications, SPLAPPLOG writes to stderr.

Debug aspects for both macros are specified as comma-separated list of strings, which are used to filter out the log or trace messages. SPL automatically adds a prefix to the name of the current operator as a debug aspect.

The SPLAPPTRC macro

Use the SPLAPPTRC macro to create trace entries in the processing element (PE) trace files.

An SPL operator runs in the context of a PE, and each PE has two sets of trace files (trace files and stdout/stderr files, which includes Processing Element Container (PEC) stdout/stderr files) and one set of log files (including PEC component log files). These files are accessed with the Teracloud® Streams administration tools. For example, to include debugging trace messages in the trace files, use this SPL code:

//        =level=  =message=       =debug aspects=
SPLAPPTRC(L_DEBUG, "Trace Message", "aspect1,aspect2");

The valid identifiers for the level of the SPLAPPTRC macro are L_ERROR(default), L_WARN, L_INFO, L_DEBUG, and L_TRACE. These identifiers correspond to the tracing configuration values.

The trace message can involve any expression that can be printed to a std::stringstream object by using the << operator. As an example, consider the following SPL code:

SPLAPPTRC(L_DEBUG, "The value for x is '" << x << "'", "MY_ASPECT");

Debug aspects for both macros are specified as comma-separated list of strings, which are used to filter out the log or trace messages. SPL automatically adds a prefix to the name of the current operator as a debug aspect.

Note: The SPLLOG macro is deprecated, and is replaced with the SPLAPPTRC macro. SPLLOG is mapped to SPLAPPTRC for compatibility with earlier versions.