Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes by create-pull-request action #147

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/#mbtools#cl_logger.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,6 @@ CLASS /mbtools/cl_logger IMPLEMENTATION.
"these objects could be moved into their own method
"see adt://***/sap/bc/adt/oo/classes/zcl_logger/source/main#start=391,10;end=415,61
symsg TYPE symsg,
syst_buffer TYPE syst,
loggable TYPE REF TO /mbtools/if_loggable_object,
loggable_object_messages TYPE /mbtools/if_loggable_object=>tty_messages.

Expand All @@ -643,7 +642,6 @@ CLASS /mbtools/cl_logger IMPLEMENTATION.
FIELD-SYMBOLS <exception_data> LIKE LINE OF exception_data_table.

" Remember system message since it might get changed inadvertently
syst_buffer = syst.
IF context IS NOT INITIAL.
ASSIGN context TO <context_val>.
formatted_context-value = <context_val>.
Expand Down Expand Up @@ -676,9 +674,7 @@ CLASS /mbtools/cl_logger IMPLEMENTATION.
msg_type = cl_abap_typedescr=>describe_by_data( obj_to_log ).
struct_kind = get_struct_kind( msg_type ).

IF obj_to_log IS INITIAL.
detailed_msg = add_syst_msg( syst_buffer ).
ELSEIF struct_kind = c_struct_kind-syst.
IF struct_kind = c_struct_kind-syst.
detailed_msg = add_syst_msg( obj_to_log ).
ELSEIF struct_kind = c_struct_kind-bapi.
detailed_msg = add_bapi_msg( obj_to_log ).
Expand Down
23 changes: 22 additions & 1 deletion src/#mbtools#cl_logger.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ can_create_anon_log 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_exception_with_context FOR TESTING RAISING cx_static_check.
can_log_exception_with_context FOR TESTING RAISING cx_static_check,
nothing_logged_for_empty_obj FOR TESTING RAISING cx_static_check.

ENDCLASS.

Expand Down Expand Up @@ -2008,4 +2009,24 @@ CLASS lcl_test IMPLEMENTATION.

ENDMETHOD.

METHOD nothing_logged_for_empty_obj.
DATA where_used_list TYPE bapiret2-message ##NEEDED.
DATA bapi_msgs TYPE TABLE OF bapiret2.
DATA bapi_msg TYPE bapiret2.

MESSAGE i001(bl) INTO where_used_list
WITH 'This should' '*not*' 'be logged'.
CLEAR where_used_list.

anon_log->add( bapi_msgs ).
cl_abap_unit_assert=>assert_equals( act = anon_log->length( )
exp = 0 ).
anon_log->add( bapi_msg ).
cl_abap_unit_assert=>assert_equals( act = anon_log->length( )
exp = 0 ).
anon_log->add( where_used_list ).
cl_abap_unit_assert=>assert_equals( act = anon_log->length( )
exp = 0 ).
ENDMETHOD.

ENDCLASS.
138 changes: 104 additions & 34 deletions src/#mbtools#cl_logger_factory.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ CLASS /mbtools/cl_logger_factory DEFINITION
RETURNING
VALUE(r_display_profile) TYPE REF TO /mbtools/if_logger_disp_prof.


"! Reopens specific log instance.
CLASS-METHODS open_log_by_db_number
IMPORTING
db_number TYPE balognr
settings TYPE REF TO /mbtools/if_logger_settings OPTIONAL
RETURNING
VALUE(r_log) TYPE REF TO /mbtools/if_logger.


PROTECTED SECTION.
PRIVATE SECTION.

Expand All @@ -57,6 +67,21 @@ CLASS /mbtools/cl_logger_factory DEFINITION
log_collection TYPE REF TO /mbtools/if_logger_collection,
log_display_profile TYPE REF TO /mbtools/if_logger_disp_prof.

CLASS-METHODS find_log_headers
IMPORTING
object TYPE csequence OPTIONAL
subobject TYPE csequence OPTIONAL
desc TYPE csequence OPTIONAL
db_number TYPE balognr OPTIONAL
RETURNING
VALUE(r_found_headers) TYPE balhdr_t.

CLASS-METHODS open_log_by_header
IMPORTING
header TYPE balhdr
settings TYPE REF TO /mbtools/if_logger_settings OPTIONAL
RETURNING
VALUE(r_log) TYPE REF TO /mbtools/if_logger.
ENDCLASS.


Expand Down Expand Up @@ -154,77 +179,122 @@ CLASS /mbtools/cl_logger_factory IMPLEMENTATION.


METHOD open_log.
DATA: filter TYPE bal_s_lfil,
l_object TYPE balobj_d,
l_subobject TYPE balsubobj,
extnumber TYPE balnrext,
found_headers TYPE balhdr_t,
DATA: found_headers TYPE balhdr_t,
most_recent_header TYPE balhdr.
DATA lo_log TYPE REF TO /mbtools/cl_logger.

found_headers = find_log_headers( object = object
subobject = subobject
desc = desc ).

IF lines( found_headers ) = 0.
IF create_if_does_not_exist = abap_true.
r_log = create_log( object = object
subobject = subobject
desc = desc
settings = settings ).
ENDIF.
RETURN.
ENDIF.

" Delete all but the last row.
IF lines( found_headers ) > 1.
DELETE found_headers TO ( lines( found_headers ) - 1 ).
ENDIF.
READ TABLE found_headers INDEX 1 INTO most_recent_header.

r_log = open_log_by_header( header = most_recent_header
settings = settings ).
ENDMETHOD.

METHOD open_log_by_db_number.
DATA: header TYPE balhdr,
log_headers TYPE balhdr_t.

log_headers = find_log_headers( db_number = db_number ).
IF lines( log_headers ) <> 1.
"^Should find exactly one log since db_number is unique identifier
RAISE EXCEPTION TYPE /mbtools/cx_logger.
ENDIF.

READ TABLE log_headers INDEX 1 INTO header.
r_log = open_log_by_header( header = header
settings = settings ).
ENDMETHOD.


METHOD find_log_headers.
DATA: filter TYPE bal_s_lfil,
l_object TYPE balobj_d,
l_subobject TYPE balsubobj,
extnumber TYPE balnrext,
log_numbers TYPE bal_t_logn.

l_object = object.
l_subobject = subobject.
extnumber = desc.
IF db_number IS SUPPLIED.
INSERT db_number INTO TABLE log_numbers.
ENDIF.

CALL FUNCTION 'BAL_FILTER_CREATE'
EXPORTING
i_object = l_object
i_subobject = l_subobject
i_extnumber = extnumber
i_t_lognumber = log_numbers
IMPORTING
e_s_log_filter = filter.

CALL FUNCTION 'BAL_DB_SEARCH'
EXPORTING
i_s_log_filter = filter
IMPORTING
e_t_log_header = found_headers
e_t_log_header = r_found_headers
EXCEPTIONS
log_not_found = 1.
ENDMETHOD.

IF sy-subrc = 1.
IF create_if_does_not_exist = abap_true.
r_log = create_log( object = object
subobject = subobject
desc = desc
settings = settings ).
ENDIF.
RETURN.
ENDIF.
METHOD open_log_by_header.
DATA: log_headers TYPE balhdr_t.
DATA logger TYPE REF TO /mbtools/cl_logger.
INSERT header INTO TABLE log_headers.

" Delete all but the last row. Keep the found_headers table this way so we can pass it to BAL_DB_LOAD.
IF lines( found_headers ) > 1.
DELETE found_headers TO ( lines( found_headers ) - 1 ).
"If you call BAL_DB_LOAD for a log that is already loaded, it doesn't return its handle, so don't rely on returned data
CALL FUNCTION 'BAL_DB_LOAD'
EXPORTING
i_t_log_header = log_headers
EXCEPTIONS
no_logs_specified = 1 " No logs specified
log_not_found = 2 " Log not found
log_already_loaded = 3 " Log is already loaded
OTHERS = 4.
IF sy-subrc <> 0.
RAISE EXCEPTION TYPE /mbtools/cx_logger.
ENDIF.
READ TABLE found_headers INDEX 1 INTO most_recent_header.



IF log_logger IS INITIAL.
CREATE OBJECT lo_log TYPE /mbtools/cl_logger.
CREATE OBJECT logger TYPE /mbtools/cl_logger.
ELSE.
lo_log ?= log_logger.
logger ?= log_logger.
ENDIF.

lo_log->db_number = most_recent_header-lognumber.
lo_log->handle = most_recent_header-log_handle.
logger->handle = header-log_handle.
logger->db_number = header-lognumber.

IF settings IS BOUND.
lo_log->settings = settings.
logger->settings = settings.
ELSE.
lo_log->settings = create_settings( ).
logger->settings = create_settings( ).
ENDIF.

CALL FUNCTION 'BAL_DB_LOAD'
EXPORTING
i_t_log_header = found_headers.

CALL FUNCTION 'BAL_LOG_HDR_READ'
EXPORTING
i_log_handle = lo_log->handle
i_log_handle = logger->handle
IMPORTING
e_s_log = lo_log->header.
e_s_log = logger->header.

r_log = lo_log.
r_log = logger.
ENDMETHOD.

ENDCLASS.
12 changes: 6 additions & 6 deletions src/#mbtools#if_logger.intf.abap
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ INTERFACE /mbtools/if_logger

METHODS add
IMPORTING
obj_to_log TYPE any OPTIONAL
obj_to_log TYPE any DEFAULT sy
context TYPE any OPTIONAL
callback_form TYPE csequence OPTIONAL
callback_prog TYPE csequence OPTIONAL
Expand All @@ -22,7 +22,7 @@ INTERFACE /mbtools/if_logger

METHODS a
IMPORTING
obj_to_log TYPE any OPTIONAL
obj_to_log TYPE any DEFAULT sy
context TYPE any OPTIONAL
callback_form TYPE csequence OPTIONAL
callback_prog TYPE csequence OPTIONAL
Expand All @@ -36,7 +36,7 @@ INTERFACE /mbtools/if_logger

METHODS e
IMPORTING
obj_to_log TYPE any OPTIONAL
obj_to_log TYPE any DEFAULT sy
context TYPE any OPTIONAL
callback_form TYPE csequence OPTIONAL
callback_prog TYPE csequence OPTIONAL
Expand All @@ -50,7 +50,7 @@ INTERFACE /mbtools/if_logger

METHODS w
IMPORTING
obj_to_log TYPE any OPTIONAL
obj_to_log TYPE any DEFAULT sy
context TYPE any OPTIONAL
callback_form TYPE csequence OPTIONAL
callback_prog TYPE csequence OPTIONAL
Expand All @@ -64,7 +64,7 @@ INTERFACE /mbtools/if_logger

METHODS i
IMPORTING
obj_to_log TYPE any OPTIONAL
obj_to_log TYPE any DEFAULT sy
context TYPE any OPTIONAL
callback_form TYPE csequence OPTIONAL
callback_prog TYPE csequence OPTIONAL
Expand All @@ -78,7 +78,7 @@ INTERFACE /mbtools/if_logger

METHODS s
IMPORTING
obj_to_log TYPE any OPTIONAL
obj_to_log TYPE any DEFAULT sy
context TYPE any OPTIONAL
callback_form TYPE csequence OPTIONAL
callback_prog TYPE csequence OPTIONAL
Expand Down