Skip to content

Commit

Permalink
Automatic Update LOGGER (#89)
Browse files Browse the repository at this point in the history
Automatic update from mirror
https://github.com/Marc-Bernard-Tools/Mirror-LOGGER

Co-authored-by: mbtools <[email protected]>
  • Loading branch information
github-actions[bot] and mbtools authored Jun 23, 2024
1 parent e946e79 commit 62cd49b
Show file tree
Hide file tree
Showing 3 changed files with 227 additions and 28 deletions.
123 changes: 103 additions & 20 deletions src/log/#mbtools#cl_logger.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ CLASS /mbtools/cl_logger DEFINITION
bapi_status_result TYPE i VALUE 7,
END OF c_struct_kind.

DATA sec_connection TYPE abap_bool.
DATA sec_connect_commit TYPE abap_bool.
DATA settings TYPE REF TO /mbtools/if_logger_settings.

METHODS:
Expand Down Expand Up @@ -153,9 +151,14 @@ add_structure
VALUE(detailed_msg) TYPE bal_s_msg.
METHODS add_bapi_status_result
IMPORTING
!obj_to_log TYPE any
obj_to_log TYPE any
RETURNING
VALUE(detailed_msg) TYPE bal_s_msg.
METHODS add_exception
IMPORTING
exception_data TYPE bal_s_exc
formatted_context TYPE bal_s_cont
formatted_params TYPE bal_s_parm.
ENDCLASS.


Expand Down Expand Up @@ -248,6 +251,71 @@ CLASS /mbtools/cl_logger IMPLEMENTATION.
ENDMETHOD.


METHOD add_exception.

DATA: detailed_msg TYPE bal_s_msg,
l_t100key TYPE scx_t100key,
l_inc TYPE i,
l_textid TYPE sotr_conc,
l_substitution_table TYPE sotr_params.

FIELD-SYMBOLS:
<l_attr> TYPE scx_t100key-attr1,
<l_msgv> TYPE bal_s_msg-msgv1,
<l_substitution> TYPE sotr_param.

"exception -> type OTR-message or T100-message?
cl_message_helper=>check_msg_kind( EXPORTING msg = exception_data-exception
IMPORTING t100key = l_t100key
textid = l_textid ).

IF l_textid IS NOT INITIAL.
"If it is a OTR-message
CALL FUNCTION 'BAL_LOG_EXCEPTION_ADD'
EXPORTING
i_log_handle = me->handle
i_s_exc = exception_data.
RETURN.
ENDIF.

"get the parameter for text switching
cl_message_helper=>get_text_params( EXPORTING obj = exception_data-exception
IMPORTING params = l_substitution_table ).

"exception with T100 message
detailed_msg-msgid = l_t100key-msgid.
detailed_msg-msgno = l_t100key-msgno.

DO 4 TIMES.
l_inc = sy-index - 1.
ASSIGN l_t100key-attr1 INCREMENT l_inc TO <l_attr> RANGE l_t100key.
IF sy-subrc = 0 AND <l_attr> IS NOT INITIAL.
READ TABLE l_substitution_table ASSIGNING <l_substitution> WITH KEY param = <l_attr>.
IF sy-subrc = 0 AND <l_substitution>-value IS NOT INITIAL.
ASSIGN detailed_msg-msgv1 INCREMENT l_inc TO <l_msgv> RANGE detailed_msg.
IF sy-subrc = 0.
<l_msgv> = <l_substitution>-value.
ENDIF.
ENDIF.
ENDIF.
ENDDO.

detailed_msg-msgty = exception_data-msgty.
detailed_msg-probclass = exception_data-probclass.
detailed_msg-detlevel = exception_data-detlevel.
detailed_msg-time_stmp = exception_data-time_stmp.
detailed_msg-alsort = exception_data-alsort.
detailed_msg-context = formatted_context.
detailed_msg-params = formatted_params.

CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = me->handle
i_s_msg = detailed_msg.

ENDMETHOD.


METHOD add_sprot_msg.
DATA sprot_message TYPE sprot_u.
MOVE-CORRESPONDING obj_to_log TO sprot_message.
Expand Down Expand Up @@ -484,13 +552,16 @@ CLASS /mbtools/cl_logger IMPLEMENTATION.
DATA log_handles TYPE bal_t_logh.
DATA log_numbers TYPE bal_t_lgnm.
DATA log_number TYPE bal_s_lgnm.
DATA secondary_db_conn TYPE flag.
secondary_db_conn = settings->get_usage_of_secondary_db_conn( ).

INSERT me->handle INTO TABLE log_handles.

CALL FUNCTION 'BAL_DB_SAVE'
EXPORTING
i_t_log_handle = log_handles
i_2th_connection = me->sec_connection
i_2th_connect_commit = me->sec_connect_commit
i_2th_connection = secondary_db_conn
i_2th_connect_commit = secondary_db_conn
IMPORTING
e_new_lognumbers = log_numbers.
IF me->db_number IS INITIAL.
Expand Down Expand Up @@ -713,22 +784,32 @@ CLASS /mbtools/cl_logger IMPLEMENTATION.
message_type = if_msg_output=>msgtype_success.
ENDIF.

CALL FUNCTION 'BAL_LOG_MSG_ADD_FREE_TEXT'
EXPORTING
i_log_handle = me->handle
i_msgty = message_type
i_probclass = importance
i_text = free_text_msg
i_s_context = formatted_context
i_s_params = formatted_params.
" i_detlevel = detlevel " mising in 740
TRY.
CALL FUNCTION 'BAL_LOG_MSG_ADD_FREE_TEXT'
EXPORTING
i_log_handle = me->handle
i_msgty = message_type
i_probclass = importance
i_text = free_text_msg
i_s_context = formatted_context
i_s_params = formatted_params
i_detlevel = detlevel.
CATCH cx_sy_dyn_call_param_not_found.
CALL FUNCTION 'BAL_LOG_MSG_ADD_FREE_TEXT'
EXPORTING
i_log_handle = me->handle
i_msgty = message_type
i_probclass = importance
i_text = free_text_msg
i_s_context = formatted_context
i_s_params = formatted_params.
ENDTRY.
ELSEIF exception_data_table IS NOT INITIAL.

LOOP AT exception_data_table ASSIGNING <exception_data>.
CALL FUNCTION 'BAL_LOG_EXCEPTION_ADD'
EXPORTING
i_log_handle = me->handle
i_s_exc = <exception_data>.
add_exception( exception_data = <exception_data>
formatted_context = formatted_context
formatted_params = formatted_params ).
ENDLOOP.
ELSEIF detailed_msg IS NOT INITIAL.
detailed_msg-context = formatted_context.
Expand Down Expand Up @@ -921,8 +1002,10 @@ CLASS /mbtools/cl_logger IMPLEMENTATION.

METHOD /mbtools/if_logger~free.

" Save any messages (safety)
/mbtools/if_logger~save( ).
" Save any messages (safety) only if an object has been defined
IF me->header-object IS NOT INITIAL.
/mbtools/if_logger~save( ).
ENDIF.

" Clear log from memory
CALL FUNCTION 'BAL_LOG_REFRESH'
Expand Down
125 changes: 124 additions & 1 deletion src/log/#mbtools#cl_logger.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ can_create_anon_log FOR TESTING,
can_log_rcomp FOR TESTING,
can_log_prott FOR TESTING,
can_log_sprot FOR TESTING,
can_log_bal_s_msg FOR TESTING,
can_log_bapirettab FOR TESTING,
can_log_err FOR TESTING,
can_log_chained_exceptions FOR TESTING,
Expand All @@ -96,7 +97,8 @@ can_create_anon_log FOR TESTING,
can_log_bapi_alm_return FOR TESTING,
can_log_bapi_meth_message FOR TESTING RAISING cx_static_check,
can_log_bapi_status_result FOR TESTING RAISING cx_static_check,
can_log_detlevel FOR TESTING RAISING cx_static_check.
can_log_detlevel FOR TESTING RAISING cx_static_check,
can_log_exception_with_context FOR TESTING RAISING cx_static_check.

ENDCLASS.

Expand Down Expand Up @@ -772,6 +774,56 @@ CLASS lcl_test IMPLEMENTATION.
msg = 'Did not log or fetch system message properly' ).
ENDMETHOD.

METHOD can_log_bal_s_msg.
DATA: bal_s_msg TYPE bal_s_msg,
msg_handle TYPE balmsghndl,
expected_details TYPE bal_s_msg,
actual_details TYPE bal_s_msg,
actual_text TYPE char200.

bal_s_msg-msgty = 'W'.
bal_s_msg-msgid = 'BL'.
bal_s_msg-msgno = '001'.
bal_s_msg-msgv1 = 'This'.
bal_s_msg-msgv2 = 'is'.
bal_s_msg-msgv3 = 'a'.
bal_s_msg-msgv4 = 'test'.

expected_details = bal_s_msg.

anon_log->add( bal_s_msg ).

msg_handle-log_handle = anon_log->handle.
msg_handle-msgnumber = '000001'.

CALL FUNCTION 'BAL_LOG_MSG_READ'
EXPORTING
i_s_msg_handle = msg_handle
IMPORTING
e_s_msg = actual_details
e_txt_msg = actual_text.

cl_abap_unit_assert=>assert_not_initial(
act = actual_details-time_stmp
msg = 'Did not log system message properly' ).

expected_details-msg_count = 1.
CLEAR actual_details-time_stmp.

cl_abap_unit_assert=>assert_equals(
exp = expected_details
act = actual_details
msg = 'Did not log system message properly' ).
cl_abap_unit_assert=>assert_equals(
exp = 'This is a test'
act = condense( actual_text )
msg = 'Did not log system message properly' ).
cl_abap_unit_assert=>assert_equals(
exp = abap_true
act = anon_log->has_warnings( )
msg = 'Did not log or fetch system message properly' ).
ENDMETHOD.

METHOD can_log_bapirettab.
DATA: bapi_messages TYPE bapirettab,
bapi_msg TYPE bapiret2,
Expand Down Expand Up @@ -1885,4 +1937,75 @@ CLASS lcl_test IMPLEMENTATION.

ENDMETHOD.

METHOD can_log_exception_with_context.

DATA: exception TYPE REF TO lcx_t100,
msg_handle TYPE balmsghndl,
actual_details TYPE bal_s_msg,
expected_details TYPE bal_s_msg,
exp_callback TYPE bal_s_clbk,
addl_context TYPE bezei20 VALUE 'Berlin'.

"Given
exp_callback-userexitf = 'FORM'.
exp_callback-userexitp = 'PROGRAM'.
exp_callback-userexitt = ' '.

expected_details-msgty = 'E'.
expected_details-msgid = 'SABP_UNIT'.
expected_details-msgno = '000'.
expected_details-msgv1 = 'This'.
expected_details-msgv2 = 'is'.
expected_details-msgv3 = 'a'.
expected_details-msgv4 = 'test'.

CREATE OBJECT exception
EXPORTING
id = 'SABP_UNIT'
no = '000'
msgv1 = 'This'
msgv2 = 'is'
msgv3 = 'a'
msgv4 = 'test'.

"When
anon_log->add( obj_to_log = exception
callback_form = 'FORM'
callback_prog = 'PROGRAM'
context = addl_context ).

msg_handle-log_handle = anon_log->handle.
msg_handle-msgnumber = '000001'.

CALL FUNCTION 'BAL_LOG_MSG_READ'
EXPORTING
i_s_msg_handle = msg_handle
IMPORTING
e_s_msg = actual_details.

cl_abap_unit_assert=>assert_equals(
exp = exp_callback
act = actual_details-params-callback
msg = 'Did not add callback correctly' ).

cl_abap_unit_assert=>assert_equals(
exp = addl_context
act = actual_details-context-value
msg = 'Did not add context correctly' ).

cl_abap_unit_assert=>assert_equals(
exp = 'BEZEI20'
act = actual_details-context-tabname
msg = 'Did not add context correctly' ).

CLEAR: actual_details-msg_count, actual_details-time_stmp,
actual_details-context, actual_details-params.

cl_abap_unit_assert=>assert_equals(
exp = expected_details
act = actual_details
msg = 'Did not log system message properly' ).

ENDMETHOD.

ENDCLASS.
7 changes: 0 additions & 7 deletions src/log/#mbtools#cl_logger_factory.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,6 @@ CLASS /mbtools/cl_logger_factory IMPLEMENTATION.
lo_log->settings->set_autosave( abap_false ).
ENDIF.

" Use secondary database connection to write data to database even if
" main program does a rollback (e. g. during a dump).
IF lo_log->settings->get_usage_of_secondary_db_conn( ) = abap_true.
lo_log->sec_connection = abap_true.
lo_log->sec_connect_commit = abap_true.
ENDIF.

" Set deletion date and set if log can be deleted before deletion date is reached.
lo_log->header-aldate_del = lo_log->settings->get_expiry_date( ).
lo_log->header-del_before = lo_log->settings->get_must_be_kept_until_expiry( ).
Expand Down

0 comments on commit 62cd49b

Please sign in to comment.