## 4.2.15.9.2.1.4  Writing Application Logs to the Database
You can use interface IF\_BALI\_LOG\_DB to write an application log to the database or to delete database entries. To get an instance of the interface, method GET\_INSTANCE of class CL\_BALI\_LOG\_DB is available.
To change the logs in the database, interface IF\_BALI\_LOG\_DB contains the following methods:
- SAVE\_LOG / SAVE\_LOG\_2ND\_DB\_CONNECTION: Save an application log in the database. The log is
- identified by the log object (which uses interface IF\_BAL\_LOG ). It may be required to commit the saving of the log immediately after the saving. It ensures that the log is stored, even if the application calls ROLLBACK WORK later on. Whether it is required depends on the application. Some applications want to keep the log entries after the rollback, others want to remove everything by the ROLLBACK WORK , including the log entries.
Therefore, there are two different methods to save an application log:
- SAVE\_LOG uses the default database connection. This means that the changes of the log are only committed if the application calls COMMIT\_WORK .
- SAVE\_LOG\_2ND\_DB\_CONNECTION uses a service connection to the database for the saving, and it immediately commits the saving of the log.
In addition, the optional parameter ASSIGN\_TO\_CURRENT\_APPL\_JOB is available. If this parameter is set, and if the application runs in an application job, the connection between the application log and an application job is established. The application log is visible in the application job display.
- DELETE\_LOG: Deletes an application log from the database. The log is identified by the log object (which uses interface IF\_BAL\_LOG ).
- ENQUEUE: If there is a parallel processing of the same application report, it may happen - depending on the application - that several reports try to change the same application log at the same time. In this case, one report overwrites the application log data of the other report. To avoid this, method ENQUEUE can be used to set an enqueue on the application log. The log is identified by the log object (which uses interface IF\_BAL\_LOG ).
- DEQUEUE: Clear the enqueue which was set via method ENQUEUE. The log is identified by the log object (which uses interface IF\_BAL\_LOG ).
##  Note
You can quickly access a log stored in the database using the log handle. The log handle is the UUID of the log. To enable the application to store the log handle in one of the application tables, interface IF\_BAL\_LOG offers method GET\_HANDLE which returns the log handle.
```
 Example Save a log in the database:  Sample Code ... TRY. DATA(l_log) = cl_bali_log=>create_with_header( cl_bali_header_setter=>create( object = 'ZOBJECT' subobject = 'ZSUBOBJECT' external_id = 'External ID' ) ). MESSAGE ID 'ZTEST' TYPE 'I' NUMBER '315' WITH 'A' 'B' 'C' 'D' INTO DATA(l_text). l_log->add_item( cl_bali_message_setter=>create_from_sy( ) ). cl_bali_log_db=>get_instance( )->save_log( log = l_log ). CATCH cx_bali_runtime INTO DATA(l_exception). out->write( l_exception->get_text(  ) ). ENDTRY. ... Save the same log using the second database connection:  Sample Code ... TRY. cl_bali_log_db=>get_instance( )->save_log_2nd_db_connection( log = l_log ). CATCH cx_bali_runtime INTO DATA(l_exception). out->write( l_exception->get_text(  ) ). ENDTRY. ... Delete the same log from the database:  Sample Code ... TRY. cl_bali_log_db=>get_instance( )->delete_log( log = l_log ). CATCH cx_bali_runtime INTO DATA(l_exception). out->write( l_exception->get_text(  ) ). ENDTRY. ... Delete a log from the database which uses the handle l_handle.
```
```
:  Sample Code ... DATA l_handle TYPE if_bali_log=>ty_handle. l_handle = ... TRY. DATA(l_log_db) = cl_bali_log_db=>get_instance( ). DATA(l_log) = l_log_db->load_log( handle = l_handle read_only_header = abap_true ). l_log_db->delete_log( log = l_log ). CATCH cx_bali_runtime INTO DATA(l_exception). out->write( l_exception->get_text(  ) ). ENDTRY. ...
```
The following authorization is checked before a log is deleted from the database:
Authorization object: S\_APPL\_LOG , with
- ALG\_OBJECT : Object name of the application log
- ALG\_SUBOBJ : Subobject of the application log
- ACTVT : 06