Advertisement
wikim1ch3lde

Anwendungsprotokoll in Cloud Entwicklung erstellen

Nov 30th, 2024 (edited)
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ABAP 2.49 KB | None | 0 0
  1. *** Neuen Anwendungsprotokoll erstellen
  2. "https://wiki.m1ch3l.de/Anwendungsprotokoll_in_Cloud_Entwicklung_erstellen#Neuen_Anwendungsprotokoll_erstellen
  3.  
  4. TRY.
  5.  DATA(lo_log) = cl_bali_log=>create( ).
  6. CATCH cx_bali_runtime INTO DATA(lx_runtime_exception).
  7. ENDTRY.
  8.  
  9. lo_log->set_header( header = cl_bali_header_setter=>create( object      = 'YOBJECT'
  10.                                                             subobject   = 'YSUBOBJECT'
  11.                                                             external_id = 'Ext ID' ) ).
  12.  
  13. *** Nachrichten zum Anwendungsprotokoll hinzufügen
  14.  
  15. TRY.
  16.  DATA(lo_message) = cl_bali_message_setter=>create( severity = if_bali_constants=>c_severity_error
  17.                                                           id = 'YMC_ABC'
  18.                                                       number = '000' ).
  19.   lo_log->add_item( item = lo_message ).
  20.  
  21.   lo_log->add_item( item = cl_bali_message_setter=>create_from_sy( ) ).
  22.  
  23.   DATA(lo_free_text) = cl_bali_free_text_setter=>create( severity = if_bali_constants=>c_severity_error
  24.                                                              text = 'Some Error Text' ).
  25.   lo_log->add_item( item = l_free_text ).
  26.  
  27.   DATA(lo_exception) = cl_bali_exception_setter=>create( severity  = if_bali_constants=>c_severity_error
  28.                                                          exception = lo_ref ).
  29.   lo_log->add_item( item = l_exception ).
  30.  CATCH cx_bali_runtime INTO DATA(lx_runtime_exception).
  31. ENDTRY.
  32.  
  33. *** Anwendungsprotokoll auf die Datenbank speichern
  34.  
  35. "Es gibt zwei Methoden zum Speichern des Logs:
  36. "SAVE_LOG: verwendet die Standarddatenbankverbindung. Dies bedeutet, dass das Protokoll nur dann auf die Datenbank geschrieben wird, wenn "die Anwendung COMMIT_WORK aufruft.
  37. "SAVE_LOG_2ND_DB_CONNECTION: verwendet zum Speichern ein Service, der das Protokoll direkt auf die Datenbank commited
  38.  
  39. TRY.
  40.  cl_bali_log_db=>get_instance( )->save_log( log = lo_log ).
  41.  cl_bali_log_db=>get_instance( )->save_log_2nd_db_connection( log = lo_log ).
  42. CATCH cx_bali_runtime INTO DATA(lx_runtime_exception).
  43. ENDTRY.
  44.  
  45. *** Anwendungsprotokoll aus dem Speicher löschen / Prüfung Speicher gelöscht
  46.  
  47. TRY.
  48.  lo_log->release_memory( ).  
  49.  IF lo_log->is_invalidated( ).
  50.  ENDIF
  51. CATCH cx_bali_runtime INTO DATA(lx_runtime_exception).
  52.  lo_runtime_exception->get_text(  ).
  53. ENDTRY.
  54.  
  55. *** Anwendungsprotokoll löschen
  56.  
  57. TRY.
  58.   cl_bali_log_db=>get_instance( )->delete_log( log = l_log ).
  59.  CATCH cx_bali_runtime INTO DATA(lx_runtime_exception).
  60. ENDTRY.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement