Add messages - SchwarzIT/sap-usi-logging-api GitHub Wiki

The log writer offers three methods, that will append a message to the log:

  • add_exception
  • add_free_text
  • add_message

As a rule of thumb, all parameters, that are not needed to get a text for the log message are optional and will use reasonable defaults.

Simple calls

The following examples show the simplest possible call to the API.

logger->add_exception( exception ).
 
logger->add_free_text( `Some free text` ).
 
logger->add_message( i_message_class      = '38'
                     i_message_number     = '000'
                     i_message_variable_1 = 'A short test message' ).

logger->add_message_from_sy_fields( ).

Complex call

The following call uses all parameters of method add_exception and shows, what the API is capable of.

logger->add_exception(
  i_problem_class   = /usi/cl_bal_enum_problem_class=>other
  i_detail_level    = /usi/cl_bal_enum_detail_level=>detail_level_1
  i_message_type    = /usi/cl_bal_enum_message_type=>error
  i_exception       = exception
  i_log_previous    = abap_true
  i_details         = NEW /usi/cl_bal_dc_collection( )->insert(
                        NEW /usi/cl_bal_dc_itab(
                          i_internal_table = table
                          i_title          = /usi/cl_bal_tc_report_text_c40=>create(
                                               i_text_key = 'DYN'
                                               i_text     = text-dyn
                                             )
                          i_fieldcatalog   = field_catalog
                        )
                      )->insert(
                        NEW /usi/cl_bal_dc_html(
                          i_html_document  = `<html><head/><body><p>Test</p></body><//html>`
                          i_document_title = NEW /usi/cl_bal_tc_literal_c40( `Document title` )
                        )
                      )
  i_message_context = VALUE #( tabname = 'T000'
                               value   = VALUE t000( mandt = 123 ) )
).

Important parameters

Parameter Description Suitable Values Default
i_problem_class Message severity

Correlates with the log level and will be used control the detail level of the log. If the severity is not high enough, the message will be ignored.
Enum-class /USI/CL_BAL_ENUM_PROBLEM_CLASS Other (Lowest)
i_log_previous For exceptions only. ABAP_TRUE will (recursively) create log messages for attribute previous.

Data container(s) passed with i_details will be attached to the message of the passed exception.

If any exception has public instance attributes, which are data containers, they will be automatically attached to the message of the respective exception.
ABAP_TRUE, ABAP_FALSE ABAP_TRUE
i_details Accepts data containers or data container collections. Every class implementing /USI/IF_BAL_MESSAGE_DETAILS.

They are all named /USI/CL_BAL_DC_* (DC stands for data container).
None

NOTE: If i_log_previous is set to ABAP_TRUE and i_details is supplied, the data container(s) of i_details will only be added to the passed exception, but NOT to the previous exceptions. Duplicating the data containers would not be useful and as they were passed along with the main exception, they "belong" to it.

⚠️ **GitHub.com Fallback** ⚠️