AbapGit
A source-verified project description is not available yet. Open the detail page or wait for a manual refresh.
Source facts need a manual refresh
Message Logger for ABAP Cloud
Message Logger for ABAP Cloud
A logger class for the most use-cases in ABAP Cloud. Focus is the logging of messages and types with the posibility to save the log to the Application Logs.
Support of ABAP Cloud (ABAP Environment, Public Cloud and Private Cloud S/4HANA 2023+) with key capabilities:
You can configure the log during the creation. Here are the different settings explained. All settions and fields are optional.
| Field | Description |
|---|---|
| object | Application Log - Object |
| subobject | Application Log - Subobject |
| external_id | Application Log - External ID |
| default_message_class | Default message class (add_message) |
| default_message_type | Default message_type (add_message, text and exception); Default E |
| no_stacked_exceptions | Only the top exception is extracted |
| save_with_job | Save the log with the Application Job |
| use_2nd_db_connection | Use the 2nd connection to save log (Works with rollback work) |
| emergency_logging | The messages are logged immediately, but performance is not particularly good. Saving is not necessary. |
| configuration | Configuration object for archive settings |
You can create your own configuration, if you want to overwrite archive settings from ZCL_AML_DEFAULT_CONFIG.
Methods to add messages to the object:
| Method | Description |
|---|---|
| add_message | T100 message |
| add_message_bapi | BAPIRET2 structure |
| add_message_bapis | BAPIRET2 table |
| add_message_exception | Any exception (also stacked) |
| add_message_system | System variables (SY) |
| add_message_text | Generic text or string |
| add_message_xco | Single XCO message |
| add_message_xcos | XCO message container |
Methods to get the collected messages:
| Method | Description |
|---|---|
| get_messages | Internal Format (UTC Timestamp, Type, SYMSG, BALI object) |
| get_messages_bapi | BAPIRET2 table |
| get_messages_flat | String table |
| get_messages_rap | Exceptions with interface IF_ABAP_BEHV_MESSAGE |
| get_messages_xco | XCO message container |
Methods that help to get more informations:
| Method | Description |
|---|---|
| get_number_of_messages | Returns the number of collected messages |
| has_error | Check the messages for Error (AEX) |
| has_warning | Check the messages for Warnings (WAEX) |
| merge_logs | Merge another log into this one |
| save | Save messages to application log |
| search_message | Search for a message in the log |
The framework is tested using unit tests, and currently all components are covered. If errors or enhancements are made, we would expand the unit tests.
Here you get some informations, how to use the log. You could also check the Unit Tests for message handling.
The normal creation of a log object.
DATA(log) = zcl_aml_log_factory=>create( ).
When you want to set some settings in the class, manage them via the constructor.
DATA(log) = zcl_aml_log_factory=>create( VALUE #( default_message_class = 'Z_AML'
default_message_type = 'I' ) ).
If you want to reuse the log or havn't saved it, you can use the Singleton principle. You can get the DEFAULT log or create different versions with the identification.
DATA(log) = zcl_aml_log_factory=>get_instance( ).
Add messages via the different methods. Here to add a simple T100 message:
log->add_message( '001' ).
... or if you have catched an exception:
CATCH cx_bali_runtime INTO DATA(bali_error).
log->add_message_exception( bali_error ).
ENDTRY.
If you want to validate the erros, you could use the helper methods to check for errors.
IF log->has_error( ).
ENDIF
To save the log you simple need to call the save method. Ensure that the settings
log->save( ).
If you want to use the where-used list of messages without creating dummy variables each time and using pragmas for ATC and ABAP Cleaner, you can use the corresponding variable in the log directly in your code before logging the message.
MESSAGE s005(z_aml) INTO log->message_text.
log->add_message_system( ).
The framework catch possible exceptions and wrapps it in a NO_CHECK exception ZCX_AML_ERROR. For example if you want to save the log and an instance is not created, the exception could be raised.