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

Read messages from log with context #164

Open
larsip opened this issue Mar 14, 2024 · 4 comments
Open

Read messages from log with context #164

larsip opened this issue Mar 14, 2024 · 4 comments

Comments

@larsip
Copy link
Contributor

larsip commented Mar 14, 2024

There is no support for reading the messages in log with context.

When reading messages from log using method export_to_table the result is of type bapirettab.

It would be nice if it was a possibility to get the result as a table of bal_s_msg (or bal_s_msg extented with message as text), so context was available.

@vidyadharg
Copy link
Contributor

Hi,

I would code as follows.
Junta thoughts pls.

"INTERFACE zif_logger method to export message along with context
METHOD:
   export_msg_context_tab
    IMPORTING
	  iv_context_structure type CLIKE
	RETURNING
	    " ITAB with fields from BAPIRETTAB + context fields
        VALUE(r_msgtab) type any.


  METHOD zif_logger~export_msg_context_tab.
    DATA:
      lt_t_msg        TYPE bal_t_msg,
      log_handle      TYPE bal_t_logh,
      message_handles TYPE bal_t_msgh,
      lw_s_msg        TYPE bal_s_msg,
      lw_s_show       TYPE bal_s_show,
      dref            TYPE REF TO data,
      exception_log   TYPE bal_s_excr,
      exception_msg   TYPE char255.

    FIELD-SYMBOLS:
      <table_of_messages> TYPE STANDARD TABLE,
      <message_line>      TYPE any,
      <context_val>       TYPE any,
      <msg_handle>        TYPE balmsghndl.

    ASSIGN r_msgtab TO <table_of_messages>.

    IF iv_context_structure IS NOT INITIAL.
      CREATE DATA dref TYPE (iv_context_structure).
      ASSIGN dref->* TO <context_val>.
      CLEAR dref.
    ENDIF.

    INSERT handle INTO TABLE log_handle.

    CALL FUNCTION 'BAL_GLB_SEARCH_MSG'
      EXPORTING
        i_t_log_handle = log_handle
      IMPORTING
        e_t_msg_handle = message_handles
      EXCEPTIONS
        msg_not_found  = 0.

    LOOP AT message_handles ASSIGNING <msg_handle>.
      CLEAR : lw_s_msg, lw_s_show.
      CALL FUNCTION 'BAL_LOG_MSG_READ'
        EXPORTING
          i_s_msg_handle  = <msg_handle>
        IMPORTING
          e_s_msg         = lw_s_msg
          e_txt_msgty     = lw_s_show-t_msgty
          e_txt_msgid     = lw_s_show-t_msgid
          e_txt_detlevel  = lw_s_show-t_detlevel
          e_txt_probclass = lw_s_show-t_probclss
          e_txt_msg       = lw_s_show-t_msg
        EXCEPTIONS
          OTHERS          = 1.
      IF sy-subrc = 0.

        APPEND INITIAL LINE TO <table_of_messages> ASSIGNING <message_line>.

        IF <context_val> IS ASSIGNED.
          <context_val>  =  lw_s_msg-context-value.
          MOVE-CORRESPONDING <context_val>  TO <message_line>.
        ENDIF.

*       set the message type icon
        CASE lw_s_msg-msgty.
          WHEN 'A'.         lw_s_show-icon_msgty = icon_alert.
          WHEN 'E'.         lw_s_show-icon_msgty = icon_led_red.
          WHEN 'W'.         lw_s_show-icon_msgty = icon_led_yellow.
          WHEN 'S' OR 'I'.  lw_s_show-icon_msgty = icon_led_green.
          WHEN OTHERS.      lw_s_show-icon_msgty = icon_led_inactive.
        ENDCASE.

        MOVE-CORRESPONDING lw_s_msg TO : lw_s_show, <message_line>.
        MOVE-CORRESPONDING lw_s_show TO <message_line>.
      ELSE.

        DATA e_txt_msgty TYPE c .
        DATA e_txt_detlevel TYPE c .
        DATA e_ltxt_msg TYPE string.
        DATA e_txt_probclass TYPE c.
        DATA e_warning_text_not_found TYPE boolean.
        DATA e_exists_on_db TYPE boolean.

        CALL FUNCTION 'BAL_LOG_EXCEPTION_READ'
          EXPORTING
            i_s_msg_handle           = <msg_handle> " Message handle
            i_langu                  = sy-langu         " Language
          IMPORTING
            e_s_exc                  = exception_log    " Exception data
            e_exists_on_db           = e_exists_on_db   " Message Already Exists on the Database
            e_txt_msgty              = e_txt_msgty      " Error type text
            e_txt_detlevel           = e_txt_detlevel   " Level of detail text
            e_txt_probclass          = e_txt_probclass  " Problem class text
            e_txt_msg                = exception_msg    " Text for Exception (Formatted)
            e_ltxt_msg               = e_ltxt_msg       " Long Text for Exception (Formatted)
            e_warning_text_not_found = e_warning_text_not_found " At least one text not found
          EXCEPTIONS
            log_not_found            = 1                " Log not found
            msg_not_found            = 2                " Message not found
            OTHERS                   = 3.

        IF sy-subrc = 0.
		"this is pending
        ENDIF.
      ENDIF.
    ENDLOOP.
  ENDMETHOD.

@mbtools
Copy link
Contributor

mbtools commented Apr 16, 2024

Closed by #163

@mbtools mbtools closed this as completed Apr 16, 2024
@larsip
Copy link
Contributor Author

larsip commented May 14, 2024

Hallo @mbtools ,

It is not the same issue.

It is me who made #163 as a fix for #161, so it surprise me, if I have made a fix for this issue 3 weeks before I created this one and couldn't remember.

This is about reading the log as a table like method export_to_table but with support for reading the context to.

When times come I will create a fork and a issue that will match.

@mbtools mbtools reopened this May 14, 2024
@mbtools
Copy link
Contributor

mbtools commented May 14, 2024

got it. looking forward to your PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants