forked from ABAP-Logger/ABAP-Logger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzcl_logger.slnk
1202 lines (1051 loc) · 54.9 KB
/
zcl_logger.slnk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<CLAS CLSNAME="ZCL_LOGGER" VERSION="1" LANGU="E" DESCRIPT="Interface to Application Log" UUID="005056945E9B1EE48CDAF5EF425E8D81" CATEGORY="00" EXPOSURE="0" STATE="1" RELEASE="0" CLSCCINCL="X" FIXPT="X" UNICODE="X" CLSBCCAT="00" WITH_UNIT_TESTS="X" DURATION_TYPE="0 " RISK_LEVEL="0 ">
<publicSection>class ZCL_LOGGER definition
public
create private .
public section.
*"* public components of class ZCL_LOGGER
*"* do not include other source files here!!!
data HEADER type BAL_S_LOG read-only .
data HANDLE type BALLOGHNDL read-only .
data DB_NUMBER type BALOGNR read-only .
class-methods NEW
importing
!OBJECT type CSEQUENCE optional
!SUBOBJECT type CSEQUENCE optional
!DESC type CSEQUENCE optional
!CONTEXT type SIMPLE optional
returning
value(R_LOG) type ref to ZCL_LOGGER .
type-pools ABAP .
class-methods OPEN
importing
!OBJECT type CSEQUENCE
!SUBOBJECT type CSEQUENCE
!DESC type CSEQUENCE optional
!CREATE_IF_DOES_NOT_EXIST type ABAP_BOOL default ABAP_FALSE
returning
value(R_LOG) type ref to ZCL_LOGGER .
methods ADD
importing
!OBJ_TO_LOG type ANY optional
!CONTEXT type SIMPLE optional
!CALLBACK_FORM type CSEQUENCE optional
!CALLBACK_PROG type CSEQUENCE optional
!CALLBACK_FM type CSEQUENCE optional
!TYPE type SYMSGTY optional
!IMPORTANCE type BALPROBCL optional
preferred parameter OBJ_TO_LOG
returning
value(SELF) type ref to ZCL_LOGGER .
methods A
importing
!OBJ_TO_LOG type ANY optional
!CONTEXT type SIMPLE optional
!CALLBACK_FORM type CSEQUENCE optional
!CALLBACK_PROG type CSEQUENCE optional
!CALLBACK_FM type CSEQUENCE optional
!IMPORTANCE type BALPROBCL optional
preferred parameter OBJ_TO_LOG
returning
value(SELF) type ref to ZCL_LOGGER .
methods E
importing
!OBJ_TO_LOG type ANY optional
!CONTEXT type SIMPLE optional
!CALLBACK_FORM type CSEQUENCE optional
!CALLBACK_PROG type CSEQUENCE optional
!CALLBACK_FM type CSEQUENCE optional
!IMPORTANCE type BALPROBCL optional
preferred parameter OBJ_TO_LOG
returning
value(SELF) type ref to ZCL_LOGGER .
methods W
importing
!OBJ_TO_LOG type ANY optional
!CONTEXT type SIMPLE optional
!CALLBACK_FORM type CSEQUENCE optional
!CALLBACK_PROG type CSEQUENCE optional
!CALLBACK_FM type CSEQUENCE optional
!IMPORTANCE type BALPROBCL optional
preferred parameter OBJ_TO_LOG
returning
value(SELF) type ref to ZCL_LOGGER .
methods I
importing
!OBJ_TO_LOG type ANY optional
!CONTEXT type SIMPLE optional
!CALLBACK_FORM type CSEQUENCE optional
!CALLBACK_PROG type CSEQUENCE optional
!CALLBACK_FM type CSEQUENCE optional
!IMPORTANCE type BALPROBCL optional
preferred parameter OBJ_TO_LOG
returning
value(SELF) type ref to ZCL_LOGGER .
methods S
importing
!OBJ_TO_LOG type ANY optional
!CONTEXT type SIMPLE optional
!CALLBACK_FORM type CSEQUENCE optional
!CALLBACK_PROG type CSEQUENCE optional
!CALLBACK_FM type CSEQUENCE optional
!IMPORTANCE type BALPROBCL optional
preferred parameter OBJ_TO_LOG
returning
value(SELF) type ref to ZCL_LOGGER .
methods POPUP .
methods FULLSCREEN .</publicSection>
<protectedSection>protected section.
*"* protected components of class ZCL_LOGGER
*"* do not include other source files here!!!</protectedSection>
<privateSection>private section.
*"* private components of class ZCL_LOGGER
*"* do not include other source files here!!!
type-pools ABAP .
data AUTO_SAVE type ABAP_BOOL .</privateSection>
<localImplementation>*"* use this source file for the definition and implementation of
*"* local helper classes, interface definitions and type
*"* declarations</localImplementation>
<localTypes>*"* use this source file for any type of declarations (class
*"* definitions, interfaces or type declarations) you need for
*"* components in the private section</localTypes>
<localMacros>*"* use this source file for any macro definitions you need
*"* in the implementation part of the class</localMacros>
<localTestClasses>CLASS lcl_test DEFINITION FOR TESTING
DURATION SHORT
RISK LEVEL HARMLESS.
*?#<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
*?<asx:values>
*?<TESTCLASS_OPTIONS>
*?<TEST_CLASS>lcl_Test
*?</TEST_CLASS>
*?<TEST_MEMBER>f_Cut
*?</TEST_MEMBER>
*?<OBJECT_UNDER_TEST>ZCL_LOGGER
*?</OBJECT_UNDER_TEST>
*?<OBJECT_IS_LOCAL/>
*?<GENERATE_FIXTURE/>
*?<GENERATE_CLASS_FIXTURE/>
*?<GENERATE_INVOCATION/>
*?<GENERATE_ASSERT_EQUAL/>
*?</TESTCLASS_OPTIONS>
*?</asx:values>
*?</asx:abap>
PRIVATE SECTION.
DATA:
anon_log TYPE REF TO zcl_logger,
named_log TYPE REF TO zcl_logger,
reopened_log TYPE REF TO zcl_logger.
CLASS-METHODS:
class_setup.
* class_teardown.
METHODS:
setup,
teardown,
get_first_message
IMPORTING log_handle TYPE balloghndl
RETURNING value(msg) TYPE char255,
get_messages
IMPORTING
log_handle TYPE balloghndl
EXPORTING
texts TYPE table_of_strings
msg_details TYPE bal_t_msg,
can_create_anon_log FOR TESTING,
can_create_named_log FOR TESTING,
can_reopen_log FOR TESTING,
can_open_or_create FOR TESTING,
can_add_log_context FOR TESTING,
can_add_to_log FOR TESTING,
can_add_to_named_log FOR TESTING,
auto_saves_named_log FOR TESTING,
auto_saves_reopened_log FOR TESTING,
can_log_string FOR TESTING,
can_log_char FOR TESTING,
can_log_bapiret2 FOR TESTING,
can_log_bapirettab FOR TESTING,
can_log_err FOR TESTING,
can_log_batch_msgs FOR TESTING,
can_add_msg_context FOR TESTING,
can_add_callback_sub FOR TESTING,
can_add_callback_fm FOR TESTING,
must_use_factory FOR TESTING,
can_use_and_chain_aliases FOR TESTING.
ENDCLASS. "lcl_Test
CLASS lcl_test IMPLEMENTATION.
METHOD class_setup.
zcl_logger=>new(
object = 'ABAPUNIT'
subobject = 'LOGGER'
desc = 'Log saved in database' )->add( 'This message is in the database' ).
ENDMETHOD.
METHOD setup.
anon_log = zcl_logger=>new( ).
named_log = zcl_logger=>new( object = 'ABAPUNIT'
subobject = 'LOGGER'
desc = `Hey it's a log` ).
reopened_log = zcl_logger=>open( object = 'ABAPUNIT'
subobject = 'LOGGER'
desc = 'Log saved in database' ).
ENDMETHOD.
METHOD can_create_anon_log.
cl_aunit_assert=>assert_bound(
act = anon_log
msg = 'Cannot Instantiate Anonymous Log' ).
ENDMETHOD.
METHOD can_create_named_log.
cl_aunit_assert=>assert_bound(
act = named_log
msg = 'Cannot Instantiate Named Log' ).
ENDMETHOD.
METHOD can_reopen_log.
cl_aunit_assert=>assert_bound(
act = reopened_log
msg = 'Cannot Reopen Log from DB' ).
ENDMETHOD.
METHOD can_open_or_create.
DATA: created_log TYPE REF TO zcl_logger,
handles TYPE bal_t_logh.
CALL FUNCTION 'BAL_GLB_MEMORY_REFRESH'. "Close Logs
reopened_log = zcl_logger=>open( object = 'ABAPUNIT'
subobject = 'LOGGER'
desc = 'Log saved in database'
create_if_does_not_exist = abap_true ).
created_log = zcl_logger=>open( object = 'ABAPUNIT'
subobject = 'LOGGER'
desc = 'Log not in database'
create_if_does_not_exist = abap_true ).
CALL FUNCTION 'BAL_GLB_SEARCH_LOG'
IMPORTING
e_t_log_handle = handles.
cl_aunit_assert=>assert_equals(
exp = 2
act = lines( handles )
msg = 'Did not create nonexistent log from OPEN' ).
ENDMETHOD.
METHOD can_add_log_context.
DATA: log TYPE REF TO zcl_logger,
random_currency_data TYPE t001a,
act_header TYPE bal_s_log.
random_currency_data-mandt = sy-mandt.
random_currency_data-bukrs = '0755'.
random_currency_data-curtp = 'AB'.
random_currency_data-kurst = 'CDEF'.
random_currency_data-cursr = 'G'.
log = zcl_logger=>new( context = random_currency_data ).
CALL FUNCTION 'BAL_LOG_HDR_READ'
EXPORTING
i_log_handle = log->handle
IMPORTING
e_s_log = act_header.
cl_aunit_assert=>assert_equals(
exp = 'T001A'
act = act_header-context-tabname
msg = 'Did not add context to log' ).
cl_aunit_assert=>assert_equals(
exp = random_currency_data
act = act_header-context-value
msg = 'Did not add context to log' ).
endmethod.
METHOD can_add_to_log.
DATA: dummy TYPE c.
MESSAGE s001(00) WITH 'I' 'test' 'the' 'logger.' INTO dummy.
anon_log->add( ).
cl_aunit_assert=>assert_equals(
exp = 'Itestthelogger.'
act = get_first_message( anon_log->handle )
msg = 'Did not log system message properly' ).
ENDMETHOD.
METHOD can_add_to_named_log.
DATA: dummy TYPE c.
MESSAGE s001(00) WITH 'Testing' 'a' 'named' 'logger.' INTO dummy.
named_log->add( ).
cl_aunit_assert=>assert_equals(
exp = 'Testinganamedlogger.'
act = get_first_message( named_log->handle )
msg = 'Did not write to named log' ).
ENDMETHOD.
METHOD auto_saves_named_log.
DATA: dummy TYPE c,
log_numbers TYPE bal_t_logn.
MESSAGE s004(rcc_test) WITH 'Testing' 'logger' 'that' 'saves.' INTO dummy.
named_log->add( ).
CALL FUNCTION 'BAL_GLB_MEMORY_REFRESH'.
APPEND named_log->db_number TO log_numbers.
CALL FUNCTION 'BAL_DB_LOAD'
EXPORTING
i_t_lognumber = log_numbers.
cl_aunit_assert=>assert_equals(
exp = 'Message: Testing logger that saves.'
act = get_first_message( named_log->handle )
msg = 'Did not write to named log' ).
ENDMETHOD.
METHOD auto_saves_reopened_log.
DATA: log_numbers TYPE bal_t_logn,
act_texts TYPE table_of_strings,
act_text TYPE string.
reopened_log->add( 'This is another message in the database' ).
CALL FUNCTION 'BAL_GLB_MEMORY_REFRESH'.
APPEND reopened_log->db_number TO log_numbers.
CALL FUNCTION 'BAL_DB_LOAD'
EXPORTING
i_t_lognumber = log_numbers.
get_messages( EXPORTING log_handle = reopened_log->handle
IMPORTING texts = act_texts ).
READ TABLE act_texts INDEX 1 INTO act_text.
cl_aunit_assert=>assert_equals(
exp = 'This message is in the database'
act = act_text
msg = 'Did not autosave to reopened log' ).
READ TABLE act_texts INDEX 2 INTO act_text.
cl_aunit_assert=>assert_equals(
exp = 'This is another message in the database'
act = act_text
msg = 'Did not autosave to reopened log' ).
ENDMETHOD.
METHOD can_log_string.
DATA: stringmessage TYPE string VALUE `Logging a string, guys!`.
anon_log->add( stringmessage ).
cl_aunit_assert=>assert_equals(
exp = stringmessage
act = get_first_message( anon_log->handle )
msg = 'Did not log system message properly' ).
ENDMETHOD.
METHOD can_log_char.
DATA: charmessage TYPE char70 VALUE 'Logging a char sequence!'.
anon_log->add( charmessage ).
cl_aunit_assert=>assert_equals(
exp = charmessage
act = get_first_message( anon_log->handle )
msg = 'Did not log system message properly' ).
ENDMETHOD.
METHOD can_log_bapiret2.
DATA: bapi_msg TYPE bapiret2,
msg_handle TYPE balmsghndl,
expected_details TYPE bal_s_msg,
actual_details TYPE bal_s_msg,
actual_text TYPE char200.
expected_details-msgty = bapi_msg-type = 'W'.
expected_details-msgid = bapi_msg-id = 'BL'.
expected_details-msgno = bapi_msg-number = '001'.
expected_details-msgv1 = bapi_msg-message_v1 = 'This'.
expected_details-msgv2 = bapi_msg-message_v2 = 'is'.
expected_details-msgv3 = bapi_msg-message_v3 = 'a'.
expected_details-msgv4 = bapi_msg-message_v4 = 'test'.
anon_log->add( bapi_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_aunit_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_aunit_assert=>assert_equals(
exp = expected_details
act = actual_details
msg = 'Did not log system message properly' ).
cl_aunit_assert=>assert_equals(
exp = 'This is a test'
act = condense( actual_text )
msg = 'Did not log system message properly' ).
ENDMETHOD.
METHOD can_log_bapirettab.
DATA: bapi_messages TYPE bapirettab,
bapi_msg TYPE bapiret2,
exp_texts TYPE table_of_strings,
exp_text TYPE string,
exp_details TYPE bal_t_msg,
exp_detail TYPE bal_s_msg,
act_texts TYPE table_of_strings,
act_text TYPE string,
act_details TYPE bal_t_msg,
act_detail TYPE bal_s_msg.
DEFINE messages_are.
exp_detail-msgty = bapi_msg-type = &1.
exp_detail-msgid = bapi_msg-id = &2.
exp_detail-msgno = bapi_msg-number = &3.
exp_detail-msgv1 = bapi_msg-message_v1 = &4.
exp_detail-msgv2 = bapi_msg-message_v2 = &5.
exp_detail-msgv3 = bapi_msg-message_v3 = &6.
exp_detail-msgv4 = bapi_msg-message_v4 = &7.
exp_text = |{ exp_detail-msgv1 } { exp_detail-msgv2 } {
exp_detail-msgv3 } { exp_detail-msgv4 }|.
append bapi_msg to bapi_messages.
append exp_detail to exp_details.
append exp_text to exp_texts.
END-OF-DEFINITION.
messages_are: 'S' 'BL' '001' 'This' 'is' 'happy' 'message',
'W' 'BL' '001' 'This' 'is' 'warning' 'message',
'E' 'BL' '001' 'This' 'is' 'angry' 'message'.
anon_log->add( bapi_messages ).
get_messages( EXPORTING log_handle = anon_log->handle
IMPORTING texts = act_texts
msg_details = act_details ).
DO 3 TIMES.
READ TABLE act_details INTO act_detail INDEX sy-index.
READ TABLE exp_details INTO exp_detail INDEX sy-index.
cl_aunit_assert=>assert_not_initial(
act = act_detail-time_stmp
msg = 'Did not log system message properly' ).
exp_detail-msg_count = 1.
CLEAR act_detail-time_stmp.
cl_aunit_assert=>assert_equals(
exp = exp_detail
act = act_detail
msg = 'Did not log bapirettab properly' ).
READ TABLE act_texts INTO act_text INDEX sy-index.
READ TABLE exp_texts INTO exp_text INDEX sy-index.
cl_aunit_assert=>assert_equals(
exp = exp_text
act = condense( act_text )
msg = 'Did not log bapirettab properly' ).
ENDDO.
ENDMETHOD.
METHOD can_log_err.
DATA: impossible_int TYPE i,
err TYPE REF TO cx_sy_zerodivide,
act_txt TYPE char255,
msg_handle TYPE balmsghndl.
TRY.
impossible_int = 1 / 0. "Make an error!
CATCH cx_sy_zerodivide INTO err.
anon_log->add( err ).
ENDTRY.
msg_handle-log_handle = anon_log->handle.
msg_handle-msgnumber = '000001'.
CALL FUNCTION 'BAL_LOG_EXCEPTION_READ'
EXPORTING
i_s_msg_handle = msg_handle
IMPORTING
e_txt_msg = act_txt.
cl_aunit_assert=>assert_equals(
exp = 'Division by zero'
act = act_txt
msg = 'Did not log throwable correctly' ).
ENDMETHOD.
METHOD can_log_batch_msgs.
DATA: batch_msgs TYPE TABLE OF bdcmsgcoll,
batch_msg TYPE bdcmsgcoll,
act_texts TYPE table_of_strings,
act_text TYPE string.
DEFINE messages_are.
batch_msg-msgtyp = &1.
batch_msg-msgid = &2.
batch_msg-msgnr = &3.
batch_msg-msgv1 = &4.
batch_msg-msgv2 = &5.
batch_msg-msgv3 = &6.
batch_msg-msgv4 = &7.
APPEND batch_msg TO batch_msgs.
END-OF-DEFINITION.
messages_are:
'S' 'RCC_TEST' '001' '' '' '' '',
'S' 'RCC_TEST' '002' '' '' '' '',
'S' 'RCC_TEST' '004' 'This' 'is' 'test' 'message'.
anon_log->add( batch_msgs ).
get_messages( EXPORTING log_handle = anon_log->handle
IMPORTING texts = act_texts ).
READ TABLE act_texts INDEX 1 INTO act_text.
cl_aunit_assert=>assert_equals(
exp = 'Message 1'
act = act_text
msg = 'Did not log BDC return messages correctly' ).
READ TABLE act_texts INDEX 2 INTO act_text.
cl_aunit_assert=>assert_equals(
exp = 'Message 2'
act = act_text
msg = 'Did not log BDC return messages correctly' ).
READ TABLE act_texts INDEX 3 INTO act_text.
cl_aunit_assert=>assert_equals(
exp = 'Message: This is test message'
act = act_text
msg = 'Did not log BDC return messages correctly' ).
ENDMETHOD.
METHOD can_add_msg_context.
DATA: addl_context TYPE bseg-belnr VALUE '4700012345',
msg_handle TYPE balmsghndl,
act_details TYPE bal_s_msg.
anon_log->add( obj_to_log = 'Here is some text'
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 = act_details.
cl_aunit_assert=>assert_equals(
exp = addl_context
act = act_details-context-value
msg = 'Did not add context correctly' ).
cl_aunit_assert=>assert_equals(
exp = 'BELNR_D'
act = act_details-context-tabname
msg = 'Did not add context correctly' ).
ENDMETHOD.
METHOD can_add_callback_sub.
DATA: msg_handle TYPE balmsghndl,
msg_detail TYPE bal_s_msg,
exp_callback TYPE bal_s_clbk.
anon_log->add( obj_to_log = 'Message with Callback'
callback_form = 'FORM'
callback_prog = 'PROGRAM' ).
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 = msg_detail.
exp_callback-userexitf = 'FORM'.
exp_callback-userexitp = 'PROGRAM'.
exp_callback-userexitt = ' '.
cl_aunit_assert=>assert_equals(
exp = exp_callback
act = msg_detail-params-callback
msg = 'Did not add callback correctly' ).
ENDMETHOD.
METHOD can_add_callback_fm.
DATA: msg_handle TYPE balmsghndl,
msg_detail TYPE bal_s_msg,
exp_callback TYPE bal_s_clbk.
anon_log->add( obj_to_log = 'Message with Callback'
callback_fm = 'FUNCTION' ).
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 = msg_detail.
exp_callback-userexitf = 'FUNCTION'.
exp_callback-userexitp = ' '.
exp_callback-userexitt = 'F'.
cl_aunit_assert=>assert_equals(
exp = exp_callback
act = msg_detail-params-callback
msg = 'Did not add callback correctly' ).
ENDMETHOD.
METHOD must_use_factory.
DATA: log TYPE REF TO object.
TRY.
CREATE OBJECT log TYPE ('ZCL_LOGGER').
cl_aunit_assert=>fail( 'Did not force creation via factory' ).
CATCH cx_sy_create_object_error.
"PASSED
ENDTRY.
ENDMETHOD.
METHOD can_use_and_chain_aliases.
DATA: texts TYPE table_of_strings,
text TYPE string,
msg_details TYPE bal_t_msg,
msg_detail TYPE bal_s_msg.
anon_log->a( 'Severe Abort Error!' )->e( |Here's an error!| ).
anon_log->w( 'This is a warning' )->i( `Helpful Information` ).
anon_log->s( 'Great' && 'Success' ).
get_messages( EXPORTING log_handle = anon_log->handle
IMPORTING texts = texts
msg_details = msg_details ).
READ TABLE texts INDEX 1 INTO text.
READ TABLE msg_details INDEX 1 INTO msg_detail.
cl_aunit_assert=>assert_equals(
exp = 'A'
act = msg_detail-msgty
msg = 'Didn''t log by alias' ).
cl_aunit_assert=>assert_equals(
exp = 'Severe Abort Error!'
act = text
msg = 'Didn''t log by alias' ).
READ TABLE texts INDEX 2 INTO text.
READ TABLE msg_details INDEX 2 INTO msg_detail.
cl_aunit_assert=>assert_equals(
exp = 'E'
act = msg_detail-msgty
msg = 'Didn''t log by alias' ).
cl_aunit_assert=>assert_equals(
exp = 'Here''s an error!'
act = text
msg = 'Didn''t log by alias' ).
READ TABLE texts INDEX 3 INTO text.
READ TABLE msg_details INDEX 3 INTO msg_detail.
cl_aunit_assert=>assert_equals(
exp = 'W'
act = msg_detail-msgty
msg = 'Didn''t log by alias' ).
cl_aunit_assert=>assert_equals(
exp = 'This is a warning'
act = text
msg = 'Didn''t log by alias' ).
READ TABLE texts INDEX 4 INTO text.
READ TABLE msg_details INDEX 4 INTO msg_detail.
cl_aunit_assert=>assert_equals(
exp = 'I'
act = msg_detail-msgty
msg = 'Didn''t log by alias' ).
cl_aunit_assert=>assert_equals(
exp = 'Helpful Information'
act = text
msg = 'Didn''t log by alias' ).
READ TABLE texts INDEX 5 INTO text.
READ TABLE msg_details INDEX 5 INTO msg_detail.
cl_aunit_assert=>assert_equals(
exp = 'S'
act = msg_detail-msgty
msg = 'Didn''t log by alias' ).
cl_aunit_assert=>assert_equals(
exp = 'GreatSuccess'
act = text
msg = 'Didn''t log by alias' ).
ENDMETHOD.
METHOD get_first_message.
DATA: msg_handle TYPE balmsghndl.
msg_handle-log_handle = log_handle.
msg_handle-msgnumber = '000001'.
CALL FUNCTION 'BAL_LOG_MSG_READ'
EXPORTING
i_s_msg_handle = msg_handle
IMPORTING
e_txt_msg = msg.
ENDMETHOD.
METHOD get_messages.
DATA: handle_as_table TYPE bal_t_logh,
message_handles TYPE bal_t_msgh,
msg_handle TYPE balmsghndl,
msg_detail TYPE bal_s_msg,
msg_text TYPE char255.
APPEND log_handle TO handle_as_table.
CALL FUNCTION 'BAL_GLB_SEARCH_MSG'
EXPORTING
i_t_log_handle = handle_as_table
IMPORTING
e_t_msg_handle = message_handles.
LOOP AT message_handles INTO msg_handle.
CALL FUNCTION 'BAL_LOG_MSG_READ'
EXPORTING
i_s_msg_handle = msg_handle
IMPORTING
e_s_msg = msg_detail
e_txt_msg = msg_text.
APPEND msg_detail TO msg_details.
APPEND msg_text TO texts.
ENDLOOP.
ENDMETHOD.
METHOD teardown.
CALL FUNCTION 'BAL_GLB_MEMORY_REFRESH'.
ENDMETHOD.
ENDCLASS. "lcl_Test</localTestClasses>
<classDocumentation OBJECT="ZCL_LOGGER">
<language SPRAS="E">
<textLine TDFORMAT="U1" TDLINE="&FUNCTIONALITY&"/>
<textLine TDFORMAT="AS" TDLINE="The class ZCL_LOGGER is designed to make logging in ABAP more like in"/>
<textLine TDLINE="other languages. To create a log and add messages in Android Java,"/>
<textLine TDLINE="Ruby, and Javascript, at most two lines of code are required: one to"/>
<textLine TDLINE="create the log and one to add the message. In addition, different types"/>
<textLine TDLINE="of objects can be logged by passing them to the same method. ZCL_LOGGER"/>
<textLine TDLINE="also has these strengths."/>
<textLine TDFORMAT="AS" TDLINE="An instance of this class can be passed a number of objects by different"/>
<textLine TDLINE="methods. Method ADD accepts a string, bapiret2, bdcmsgcoll, exception"/>
<textLine TDLINE="object, or a table of any of those data types. Methods A, E, W, I and S"/>
<textLine TDLINE="accept exactly the same but they add the type of message corresponding"/>
<textLine TDLINE="to their names."/>
<textLine TDFORMAT="U1" TDLINE="&RELATIONS&"/>
<textLine TDFORMAT="AS" TDLINE="ZCL_LOGGER makes a bunch of calls to function group"/>
<textLine TDFORMAT="=" TDLINE=" <DS:RE.SAPLSBAL>SBAL</>."/>
<textLine TDFORMAT="U1" TDLINE="&EXAMPLE&"/>
<textLine TDFORMAT="U3" TDLINE="Creating a Log in SLG1"/>
<textLine TDFORMAT="PE" TDLINE="DATA: log TYPE REF TO zcl_logger."/>
<textLine TDFORMAT="/" TDLINE="* If you create a log without any parameters, it will only be in memory"/>
<textLine TDFORMAT="/" TDLINE="log = zcl_logger=>new( )."/>
<textLine TDFORMAT="/"/>
<textLine TDFORMAT="/" TDLINE="* If you supply an object and subobject, the log will be created on the"/>
<textLine TDFORMAT="/" TDLINE="* database the first time a message is stored, so you can view it later"/>
<textLine TDFORMAT="/" TDLINE="* in SLG1."/>
<textLine TDFORMAT="/" TDLINE="log = zcl_logger=>new( object = 'WF'"/>
<textLine TDFORMAT="/" TDLINE=" subobject = 'NOTIFICATIONS'"/>
<textLine TDFORMAT="/" TDLINE=" desc = |Notifications on { sy-datum }| )."/>
<textLine TDFORMAT="U3" TDLINE="Logging Strings"/>
<textLine TDFORMAT="PE" TDLINE="DATA: log TYPE REF TO zcl_logger."/>
<textLine TDFORMAT="/" TDLINE="log = zcl_logger=>new( )."/>
<textLine TDFORMAT="/" TDLINE="log->s( 'This is a success message' )."/>
<textLine TDFORMAT="/" TDLINE="log->w( 'This is a warning message' )."/>
<textLine TDFORMAT="U3" TDLINE="Logging Errors"/>
<textLine TDFORMAT="PE" TDLINE="DATA: log TYPE REF TO zcl_logger,"/>
<textLine TDFORMAT="/" TDLINE=" l_err TYPE REF TO zcx_operation_failed."/>
<textLine TDFORMAT="/" TDLINE="log = zcl_logger=>new( object = 'WF' subobject = 'NOTIFICATIONS' )."/>
<textLine TDFORMAT="/" TDLINE="TRY."/>
<textLine TDFORMAT="/" TDLINE=" my_class=>do_some_operation( )."/>
<textLine TDFORMAT="/" TDLINE=" CATCH zcx_operation_failed INTO l_err."/>
<textLine TDFORMAT="/" TDLINE=" log->e( l_err )."/>
<textLine TDFORMAT="/" TDLINE="ENDTRY."/>
<textLine TDFORMAT="U3" TDLINE="Logging BAPI Messages"/>
<textLine TDFORMAT="PE" TDLINE="DATA: rtn_msgs TYPE TABLE OF bapiret2."/>
<textLine TDFORMAT="/" TDLINE="CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'"/>
<textLine TDFORMAT="/" TDLINE=" EXPORTING"/>
<textLine TDFORMAT="/" TDLINE=" parameter1 = foo"/>
<textLine TDFORMAT="/" TDLINE=" parameter2 = bar"/>
<textLine TDFORMAT="/" TDLINE=" TABLES"/>
<textLine TDFORMAT="/" TDLINE=" return = rtn_msgs."/>
<textLine TDFORMAT="/" TDLINE="IF rtn_msgs IS NOT INITIAL."/>
<textLine TDFORMAT="/" TDLINE=" log = zcl_logger=>new( object = 'ACCOUNTING' subobject = 'INTERFACES'"/>
<textLine TDLINE=")."/>
<textLine TDFORMAT="/" TDLINE=" log->add( rtn_msgs )."/>
<textLine TDFORMAT="/" TDLINE="ENDIF."/>
<textLine TDFORMAT="U3" TDLINE="Displaying a log"/>
<textLine TDFORMAT="PE" TDLINE="log->popup( )."/>
<textLine TDFORMAT="/" TDLINE="log->fullscreen( )."/>
<textLine TDFORMAT="AS"/>
<textLine TDFORMAT="U1" TDLINE="&HINTS&"/>
<textLine TDFORMAT="AS" TDLINE="Calls to the log can be chained, like:"/>
<textLine TDFORMAT="PE" TDLINE="log->e( 'An error occurred. See following:' )->e( l_err )."/>
<textLine TDFORMAT="U1" TDLINE="&FURTHER_SOURCES_OF_INF&"/>
<textLine TDFORMAT="AS" TDLINE="If you plan on modifying or adding to this class, see the local unit"/>
<textLine TDLINE="tests. You can run them and they will test the class in a number of"/>
<textLine TDLINE="different scenarios. You can set breakpoints before running unit tests"/>
<textLine TDLINE="to see the behavior in action."/>
</language>
</classDocumentation>
<typeUsage CLSNAME="ZCL_LOGGER" TYPEGROUP="ABAP" VERSION="1" TPUTYPE="0" IMPLICIT="X"/>
<forwardDeclaration>ABAP</forwardDeclaration>
<attribute CLSNAME="ZCL_LOGGER" CMPNAME="AUTO_SAVE" VERSION="1" LANGU="E" DESCRIPT="Persist Messages?" EXPOSURE="0" STATE="1" EDITORDER="3 " ATTDECLTYP="0" ATTEXPVIRT="0" TYPTYPE="1" TYPE="ABAP_BOOL" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " TYPESRC_LENG="0 "/>
<attribute CLSNAME="ZCL_LOGGER" CMPNAME="DB_NUMBER" VERSION="1" LANGU="E" DESCRIPT="Application log: log number" EXPOSURE="2" STATE="1" EDITORDER="3 " ATTDECLTYP="0" ATTRDONLY="X" ATTEXPVIRT="0" TYPTYPE="1" TYPE="BALOGNR" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " TYPESRC_LENG="0 "/>
<attribute CLSNAME="ZCL_LOGGER" CMPNAME="HANDLE" VERSION="1" LANGU="E" DESCRIPT="Application Log: Log Handle" EXPOSURE="2" STATE="1" EDITORDER="2 " ATTDECLTYP="0" ATTRDONLY="X" ATTEXPVIRT="0" TYPTYPE="1" TYPE="BALLOGHNDL" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " TYPESRC_LENG="0 "/>
<attribute CLSNAME="ZCL_LOGGER" CMPNAME="HEADER" VERSION="1" LANGU="E" DESCRIPT="Application Log: Log header data" EXPOSURE="2" STATE="1" EDITORDER="1 " ATTDECLTYP="0" ATTRDONLY="X" ATTEXPVIRT="0" TYPTYPE="1" TYPE="BAL_S_LOG" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " TYPESRC_LENG="0 "/>
<method CLSNAME="ZCL_LOGGER" CMPNAME="A" VERSION="1" LANGU="E" DESCRIPT="Log ABORT-type Message" EXPOSURE="2" STATE="1" EDITORDER="4 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_LOGGER" CMPNAME="A" SCONAME="OBJ_TO_LOG" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="ANY" PAROPTIONL="X" PARPREFERD="X"/>
<parameter CLSNAME="ZCL_LOGGER" CMPNAME="A" SCONAME="CONTEXT" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="2 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="SIMPLE" PAROPTIONL="X"/>
<parameter CLSNAME="ZCL_LOGGER" CMPNAME="A" SCONAME="CALLBACK_FORM" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="3 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="CSEQUENCE" PAROPTIONL="X"/>
<parameter CLSNAME="ZCL_LOGGER" CMPNAME="A" SCONAME="CALLBACK_PROG" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="4 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="CSEQUENCE" PAROPTIONL="X"/>
<parameter CLSNAME="ZCL_LOGGER" CMPNAME="A" SCONAME="CALLBACK_FM" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="5 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="CSEQUENCE" PAROPTIONL="X"/>
<parameter CLSNAME="ZCL_LOGGER" CMPNAME="A" SCONAME="IMPORTANCE" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="6 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="BALPROBCL" PAROPTIONL="X"/>
<parameter CLSNAME="ZCL_LOGGER" CMPNAME="A" SCONAME="SELF" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="7 " DISPID="0 " PARDECLTYP="3" PARPASSTYP="0" TYPTYPE="3" TYPE="ZCL_LOGGER"/>
<source>method A.
self = add(
obj_to_log = obj_to_log
context = context
callback_form = callback_form
callback_prog = callback_prog
callback_fm = callback_fm
type = 'A'
importance = importance ).
endmethod.</source>
</method>
<method CLSNAME="ZCL_LOGGER" CMPNAME="ADD" VERSION="1" LANGU="E" DESCRIPT="Add Message to Log" EXPOSURE="2" STATE="1" EDITORDER="3 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_LOGGER" CMPNAME="ADD" SCONAME="OBJ_TO_LOG" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="ANY" PAROPTIONL="X" PARPREFERD="X"/>
<parameter CLSNAME="ZCL_LOGGER" CMPNAME="ADD" SCONAME="CONTEXT" VERSION="1" LANGU="E" DESCRIPT="Additional context not in message text" CMPTYPE="1" MTDTYPE="0" EDITORDER="2 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="SIMPLE" PAROPTIONL="X"/>
<parameter CLSNAME="ZCL_LOGGER" CMPNAME="ADD" SCONAME="CALLBACK_FORM" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="3 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="CSEQUENCE" PAROPTIONL="X"/>
<parameter CLSNAME="ZCL_LOGGER" CMPNAME="ADD" SCONAME="CALLBACK_PROG" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="4 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="CSEQUENCE" PAROPTIONL="X"/>
<parameter CLSNAME="ZCL_LOGGER" CMPNAME="ADD" SCONAME="CALLBACK_FM" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="5 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="CSEQUENCE" PAROPTIONL="X"/>
<parameter CLSNAME="ZCL_LOGGER" CMPNAME="ADD" SCONAME="TYPE" VERSION="1" LANGU="E" DESCRIPT="Message Type" CMPTYPE="1" MTDTYPE="0" EDITORDER="6 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="SYMSGTY" PAROPTIONL="X"/>
<parameter CLSNAME="ZCL_LOGGER" CMPNAME="ADD" SCONAME="IMPORTANCE" VERSION="1" LANGU="E" DESCRIPT="1 (Severe) to 4 (Addl Info)" CMPTYPE="1" MTDTYPE="0" EDITORDER="7 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="BALPROBCL" PAROPTIONL="X"/>
<parameter CLSNAME="ZCL_LOGGER" CMPNAME="ADD" SCONAME="SELF" VERSION="1" LANGU="E" DESCRIPT="Returns Self for Chaining" CMPTYPE="1" MTDTYPE="0" EDITORDER="8 " DISPID="0 " PARDECLTYP="3" PARPASSTYP="0" TYPTYPE="3" TYPE="ZCL_LOGGER"/>
<source>METHOD add.
DATA: detailed_msg TYPE bal_s_msg,
free_text_msg TYPE char200,
msg_type TYPE REF TO cl_abap_typedescr,
msg_table_type TYPE REF TO cl_abap_tabledescr,
exception_data TYPE bal_s_exc,
log_numbers TYPE bal_t_lgnm,
log_handles TYPE bal_t_logh,
log_number TYPE bal_s_lgnm,
formatted_context TYPE bal_s_cont,
formatted_params TYPE bal_s_parm.
FIELD-SYMBOLS: <table_of_messages> TYPE any table,
<message_line> TYPE any,
<bapi_msg> TYPE bapiret2,
<bdc_msg> TYPE bdcmsgcoll,
<context_val> TYPE c.
IF context IS NOT INITIAL.
ASSIGN context TO <context_val> CASTING.
formatted_context-value = <context_val>.
formatted_context-tabname =
cl_abap_typedescr=>describe_by_data( context )->get_ddic_header( )-tabname.
ENDIF.
IF callback_fm IS NOT INITIAL.
formatted_params-callback-userexitf = callback_fm.
formatted_params-callback-userexitp = callback_prog.
formatted_params-callback-userexitt = 'F'.
ELSEIF callback_form IS NOT INITIAL.
formatted_params-callback-userexitf = callback_form.
formatted_params-callback-userexitp = callback_prog.
formatted_params-callback-userexitt = ' '.
ENDIF.
msg_type = cl_abap_typedescr=>describe_by_data( obj_to_log ).
IF obj_to_log IS INITIAL.
detailed_msg-msgty = sy-msgty.
detailed_msg-msgid = sy-msgid.
detailed_msg-msgno = sy-msgno.
detailed_msg-msgv1 = sy-msgv1.
detailed_msg-msgv2 = sy-msgv2.
detailed_msg-msgv3 = sy-msgv3.
detailed_msg-msgv4 = sy-msgv4.
ELSEIF msg_type->type_kind = cl_abap_typedescr=>typekind_oref.
exception_data-exception = obj_to_log.
exception_data-msgty = type.
exception_data-probclass = importance.
ELSEIF msg_type->type_kind = cl_abap_typedescr=>typekind_table.
ASSIGN obj_to_log TO <table_of_messages>.
LOOP AT <table_of_messages> ASSIGNING <message_line>.
add( <message_line> ).
ENDLOOP.
RETURN.
ELSEIF msg_type->absolute_name = '\TYPE=BAPIRET2'.
ASSIGN obj_to_log TO <bapi_msg>.
detailed_msg-msgty = <bapi_msg>-type.
detailed_msg-msgid = <bapi_msg>-id.
detailed_msg-msgno = <bapi_msg>-number.
detailed_msg-msgv1 = <bapi_msg>-message_v1.
detailed_msg-msgv2 = <bapi_msg>-message_v2.
detailed_msg-msgv3 = <bapi_msg>-message_v3.
detailed_msg-msgv4 = <bapi_msg>-message_v4.
ELSEIF msg_type->absolute_name = '\TYPE=BDCMSGCOLL'.
ASSIGN obj_to_log TO <bdc_msg>.
detailed_msg-msgty = <bdc_msg>-msgtyp.
detailed_msg-msgid = <bdc_msg>-msgid.
detailed_msg-msgno = <bdc_msg>-msgnr.
detailed_msg-msgv1 = <bdc_msg>-msgv1.
detailed_msg-msgv2 = <bdc_msg>-msgv2.
detailed_msg-msgv3 = <bdc_msg>-msgv3.
detailed_msg-msgv4 = <bdc_msg>-msgv4.
ELSE.
free_text_msg = obj_to_log.
ENDIF.
IF free_text_msg IS NOT INITIAL.
CALL FUNCTION 'BAL_LOG_MSG_ADD_FREE_TEXT'
EXPORTING
i_log_handle = me->handle
i_msgty = type
i_probclass = importance
i_text = free_text_msg
i_s_context = formatted_context
i_s_params = formatted_params.
ELSEIF exception_data IS NOT INITIAL.
CALL FUNCTION 'BAL_LOG_EXCEPTION_ADD'
EXPORTING
i_log_handle = me->handle
i_s_exc = exception_data.
ELSEIF detailed_msg IS NOT INITIAL.
detailed_msg-context = formatted_context.
detailed_msg-params = formatted_params.
detailed_msg-probclass = importance.
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = me->handle
i_s_msg = detailed_msg.
ENDIF.
IF auto_save = abap_true.
APPEND me->handle TO log_handles.
CALL FUNCTION 'BAL_DB_SAVE'
EXPORTING
i_t_log_handle = log_handles
IMPORTING
e_new_lognumbers = log_numbers.
IF me->db_number IS INITIAL.
READ TABLE log_numbers INDEX 1 INTO log_number.
me->db_number = log_number-lognumber.
ENDIF.
ENDIF.
self = me.
ENDMETHOD.</source>
</method>
<method CLSNAME="ZCL_LOGGER" CMPNAME="E" VERSION="1" LANGU="E" DESCRIPT="Log ERROR-type Message" EXPOSURE="2" STATE="1" EDITORDER="5 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_LOGGER" CMPNAME="E" SCONAME="OBJ_TO_LOG" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="ANY" PAROPTIONL="X" PARPREFERD="X"/>
<parameter CLSNAME="ZCL_LOGGER" CMPNAME="E" SCONAME="CONTEXT" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="2 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="SIMPLE" PAROPTIONL="X"/>
<parameter CLSNAME="ZCL_LOGGER" CMPNAME="E" SCONAME="CALLBACK_FORM" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="3 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="CSEQUENCE" PAROPTIONL="X"/>
<parameter CLSNAME="ZCL_LOGGER" CMPNAME="E" SCONAME="CALLBACK_PROG" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="4 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="CSEQUENCE" PAROPTIONL="X"/>
<parameter CLSNAME="ZCL_LOGGER" CMPNAME="E" SCONAME="CALLBACK_FM" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="5 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="CSEQUENCE" PAROPTIONL="X"/>
<parameter CLSNAME="ZCL_LOGGER" CMPNAME="E" SCONAME="IMPORTANCE" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="6 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="BALPROBCL" PAROPTIONL="X"/>
<parameter CLSNAME="ZCL_LOGGER" CMPNAME="E" SCONAME="SELF" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="7 " DISPID="0 " PARDECLTYP="3" PARPASSTYP="0" TYPTYPE="3" TYPE="ZCL_LOGGER"/>
<source>method E.
self = add(
obj_to_log = obj_to_log
context = context
callback_form = callback_form
callback_prog = callback_prog
callback_fm = callback_fm
type = 'E'