来源资料待手动核验
项目简介
ABAP Cloud-ready Logger
ABAP Cloud-ready Logger
Open Source Contribution: This project is community-driven and Open Source! 🚀
If you spot a bug or have an idea for a cool enhancement, your contributions are more than welcome. Feel free to open an Issue or submit a Pull Request.
ABAP Logger Following Clean Core Principles.ABAP Cloud Logger is a modern, lightweight, and Clean Core-compliant logging library for SAP S/4HANA and SAP BTP ABAP Environment.
It acts as a fluent wrapper around the standard class CL_BALI_LOG, simplifying the Application Log API while ensuring strict adherence to ABAP Cloud development standards.
This project is licensed under the MIT License.
The repository was created by George Drakos.
Logging is a tool I rely on almost every day while working with ABAP. I wanted to create a version that is not only simple and effective but also fully compatible with the ABAP Cloud environment. The goal is to provide an easy-to-use logger that fits naturally into cloud-ready development practices and can be integrated seamlessly into modern projects.
To start logging, get an instance of the logger by providing your Application Log Object and Subobject (defined in Eclipse as Application Log Object).
DATA(logger) = zcl_cloud_logger=>get_instance( object = 'Z_CLOUD_LOG_SAMPLE'
subobject = 'SETUP' ).
TRY.
" Your business logic here
DATA(result) = 100 / 0.
CATCH cx_sy_zerodivide INTO DATA(error).
" Pass the exception object to the logger
logger->log_exception_add( error ).
ENDTRY.
logger->log_message_add( symsg = VALUE #( msgty = 'W'
msgid = 'CL'
msgno = '000'
msgv1 = 'Test Message' ) ).
logger->log_string_add( string = 'String Add'
msgty = 'E' ).
logger->log_bapiret2_table_add(
bapiret2_t = return
min_severity = 'E' ).
logger->log_bapiret2_structure_add( VALUE #( ) ) .
SELECT * FROM i_companycode INTO TABLE @DATA(company_codes) UP TO 10 ROWS.
" Log the whole table as JSON
logger->log_data_add( company_codes ).
DATA(message_count) = logger->get_message_count( ).
DATA(messages_bapiret2) = logger->get_messages_as_bapiret2( ).
DATA(messages) = logger->get_messages( ).
DATA(messages_flat) = logger->get_messages_flat( ).
DATA(messages_rap) = logger->get_messages_rap( ).
DATA(error_exists) = logger->log_contains_error( ).
DATA(messages_exist) = logger->log_contains_messages( ).
DATA(warning_exists) = logger->log_contains_warning( ).
DATA(is_empty) = logger->log_is_empty( ).
DATA(handle) = logger->get_handle( ).
DATA(log_handle) = logger->get_log_handle( ).
logger->save_application_log( ).
data(specific_message_exists) = logger->search_message( search = VALUE #( msgid = '00' ) ).
"Get a New Log Instance
DATA(new_logger) = zcl_cloud_logger=>get_instance( object = 'Z_MY_OBJECT_NEW'
subobject = 'Z_MY_SUBOBJECT_NEW' ).
"Add Message
new_logger->log_string_add( string = 'New Logger String'
msgty = 'E' ).
"Merge with Previous Log
logger->merge_logs( new_logger ).
logger->reset_appl_log( delete_from_db = abap_true ).
" 1. Start the stopwatch
logger->start_timer( ).
" 2. Execute a code block
"SELECT FROM.....
" 3. Stop and log the duration automatically
logger->stop_timer( 'Test Timer' ).
logger->display( NEW zcl_cloud_logger_view_alv( ) ).
logger->set_context( 'Order 100' ).
logger->log_string_add( 'Price checked' )."[Order 100] Price checked logged
logger->clear_context( ).
display() method, enabling UI-agnostic log visualization (Strategy Pattern)start_timer and stop_timer methods for runtime measurement.log_bapiret2_table_add with iv_min_severity. You can now filter logs directly during import (e.g., ignore all Success messages).log_data_add allows logging of any data type (Structures/Tables). Data is automatically converted to JSON format using the XCO library.