Data Containers - SchwarzIT/sap-usi-logging-api GitHub Wiki
Data containers are used to attach additional data to log messages.
The API is shipped with a couple of useful data containers.
| Classname | Description |
|---|---|
| /USI/CL_BAL_DC_COLLECTION | Wrapper for 0-n data containers. Can be passed to every method, that would accept a single data container. |
| /USI/CL_BAL_DC_* | Name prefix for any data container shipped with this API. |
There are different groups of data containers:
| Data Container Group | Description |
|---|---|
| Renderable containers | The contained data will be rendered using an instance of CL_GUI_CONTAINER. |
| Navigation Containers | These containers do not render any output but just navigate somewhere (e.g. to source code positions). |
The API is shipped with data containers that should cover a wide range of requirements.
Some containers can be created automatically if the log level is high enough. If you need to change the content of these containers you can simply create and pass them to the respective methods of the log writer yourself. Your instance will then replace the automatically created one.
Column Multiple Use indicates if more than one instance of the respective data container can be assigned to a single log message.
| Classname | Multiple Use | Creation | Description / Content |
|---|---|---|---|
| /USI/CL_BAL_DC_CALLSTACK | No | Automatically | ABAP Callstack (Supports navigation via double click) |
| /USI/CL_BAL_DC_HTML | Yes | Manually | HTML document |
| /USI/CL_BAL_DC_ITAB | Yes | Manually | Any table (Standard / Sorted / Hashed). Supported line types:
|
| /USI/CL_BAL_DC_JSON | Yes | Manually | JSON document |
| /USI/CL_BAL_DC_RETCODE_AND_MSG | No | Manually | Return code & message (e.g. after CALL FUNCTION) |
| /USI/CL_BAL_DC_STRUCTURE | Yes | Manually | Structure (DDIC or non-DDIC) |
| /USI/CL_BAL_DC_XML | Yes | Manually | XML document |
| Classname | Multiple Use | Creation | Description / Content |
|---|---|---|---|
| /USI/CL_BAL_DC_CHILD_LOG | No | Automatically | Link to child log |
| /USI/CL_BAL_DC_PARENT_LOG | No | Automatically | Link to parent log |
| /USI/CL_BAL_DC_SRC_POS_CALLER | No | Automatically | Source code position of the caller that created this log message |
| /USI/CL_BAL_DC_SRC_POS_CX | No | Automatically | Source code position where the logged exception was raised |
The class /USI/CL_BAL_DC_COLLECTION can hold a collection of data containers and implements the same interfaces as the data containers. That makes it possible to pass a collection of data containers to any method call that would accept a single data container as input.
You can also attach data containers to your exceptions by adding a public attribute having one of the following types:
| TYPE REF TO | Wraps | Description | Remarks |
|---|---|---|---|
| /USI/IF_EXCEPTION_DETAILS | Empty Interface | ||
| /USI/IF_BAL_MESSAGE_DETAILS | /USI/IF_EXCEPTION_DETAILS | Empty Interface | |
| /USI/IF_BAL_DATA_CONTAINER_COL | /USI/IF_BAL_MESSAGE_DETAILS | Data Container Collection | Not recommended - use one of the more generic types above. |
| /USI/IF_BAL_DATA_CONTAINER | /USI/IF_BAL_MESSAGE_DETAILS | Single Data Container | Not recommended - use one of the more generic types above. |
When logging an exception the API will evaluate all public attributes of the exception object, that are object references. For each attribute a downcast to /USI/IF_BAL_DATA_CONTAINER and /USI/IF_BAL_DATA_CONTAINER_COL will be tried. If it succeeds the data containers attached to the exception will be added to the log message automatically.
The name of the attribute is completely arbitrary and multiple attributes are supported. It is recommended to use an attribute with a type that is generic enough to bind a single data container or a collection of data containers. This would make it very easy to attach virtually anything to the exception object.
If needed, additional data containers can be added, as described here.