如何使用应用日志(Application Log)
SAP的应用日志(Application Log)是用于创建,保存和分析系统消息的工具.
相关TCODE:
SLG0: Creation of Object and Sub object
SLG1: Display Application Logs
相关创建应用日志函数
BAL_LOG_CREATE --> Create log with header data
BAL_LOG_MSG_ADD --> Put message in log
BAL_DB_SAVE --> Save logs in the database
创建应用日志的处理步骤:
1: 使用TCODE:SLG0创建对象和子对象.
2: 创建对象,对象名以Z或Y开头.
3: 创建对象后,你将创建子对象.
4: 如果相应的子对象不存在,则创建子对象.
5: 这样对象和子对象就可以在应用日志中使用了.
6: 使用下面三个函数创建和保存应用日志
7: 使用'BAL_LOG_CREATE' 创建日志句柄(log handle)
8: 使用'BAL_LOG_MSG_ADD' 添加消息,
9: 使用'BAL_DB_SAVE' 保存日志
如何查看应用日志?
1. 输入TCODE: SLG1.系统将出现分析应用日志的屏幕.
2. 输入对象,子对象和外部标示符.
3. 输入时间.
4. 规定日志的原因
5. 选择日志类别和创建日志.
6. 执行.
系统将显示结果.
SAP的代码实例:
SBAL_DEMO_06
样例代码:
report sbal_demo_06 .
***********************************************************************
***********************************************************************
* REPORT SBAL_DEMO_06
*
* The application log allows to add application specific data to
* a log header or a message.
*
* One simple possibility is to use the context. This allows to
* to add the content of a (flat, non-hierarchical) DDIC-structure
* to a log header or a message (sie sub-structure 'CONTEXT' in
* structure BAL_S_LOG and BAL_S_MSG).
* There is already an example in Report SBAL_DEMO_02 for this
* (see FORM msg_add_with_context).
*
* But sometimes a simple, flat DDIC-structure is not sufficient.
* If you want to add more complex data (like an internal table,
* a complex data type, etc.) to a log or a message,
* you can use table BAL_INDX.
*
* BAL_INDX is an INDX-like table which can be filled and read
* with the ABAP-statement EXPORT/IMPORT.
* This report shows an example how to use BAL_INDEX.
*
* This report has three options:
* o create log
* o display log
* o delete log
*
* create log:
* ==========
* The log which is created consists of a log header
* and only one message. For both, log header and message
* the parameters are defined (see sub-structure 'PARAMS' in
* BAL_S_LOG and BAL_S_MSG).
* The parameters are filled and callback routines are defined.
* When the log is saved, also some internal tables containing
* further data are saved via EXPORT TO BAL_INDX
* (see FORM log_save)
*
* display log:
* ===========
* The log is searched on the database, loaded and displayed.
* When the detail of a message or the log header is selected
* by the user, the callback-routines are called.
* In this callback-routine the internal tables are read
* with 'IMPORT FROM BAL_INDX'.
* (see FORM CALLBACK_LOG_DETAIL or FORM CALLBACK_MSG_DETAIL, both
* call FORM LOAD_MY_DATA).
*
* delete log:
* ===========
* The log is searched on the database and deleted.
* This deletion also deletes the data in table BAL_INDX for this
* log.
*
***********************************************************************
***********************************************************************
***********************************************************************
******************** SELECTION SCREEN *********************************
***********************************************************************
parameters:
p_create radiobutton group par,
p_disp radiobutton group par,
p_delete radiobutton group par.
***********************************************************************
******************** CONSTANTS, TYPES, DATA ***************************
***********************************************************************
set extended check off.
include sbal_constants.
set extended check on.
tables:
bal_indx.
constants:
const_example_object type bal_s_log-object value 'BCT1',
const_example_extnumber type bal_s_log-extnumber value 'BAL_INDX',
const_name_msg_ident(9) type c value 'MSG_IDENT'.
data:
g_identifier(10) type n,
g_lognumber type balhdr-lognumber.
* these are our own data we want to save with the application log:
data:
g_my_header_data type bal_s_ex05 occurs 0 with header line,
begin of g_my_message_data occurs 0,
identifier like g_identifier,
t_my_data type bal_s_ex06 occurs 0,
end of g_my_message_data.
***********************************************************************
******************** MAIN PROGRAM *************************************
***********************************************************************
end-of-selection.
* create log
if not p_create is initial.
perform log_create.
endif.
* display log
if not p_disp is initial.
perform log_display.
endif.
* delete log
if not p_delete is initial.
perform log_delete.
endif.
***********************************************************************
************** FORMS FOR CREATION OF THE LOG *************************
***********************************************************************
*--------------------------------------------------------------------
* FORM log_create.
*--------------------------------------------------------------------
form log_create.
data:
l_log_handle type balloghndl.
* create log header with information about the carriers and
* connection which are calculated in this transaction
perform log_header_create
changing
l_log_handle.
* create the message
perform log_message_create
using
l_log_handle.
* save the application log and our data
perform log_save
using
l_log_handle.
endform.
*--------------------------------------------------------------------
* FORM log_header_create
*--------------------------------------------------------------------
form log_header_create
changing
c_log_handle type balloghndl.
data:
l_s_log type bal_s_log.
* create log header data
clear l_s_log.
l_s_log-object = const_example_object.
l_s_log-extnumber = const_example_extnumber.
* define callback routine
l_s_log-params-callback-userexitp = sy-repid.
l_s_log-params-callback-userexitf = 'CALLBACK_LOG_DETAIL'.
l_s_log-params-callback-userexitt = const_callback_form.
* create the log header
call function 'BAL_LOG_CREATE'
exporting
i_s_log = l_s_log
importing
e_log_handle = c_log_handle
exceptions
others = 1.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
* we want to store some information in the log header
* to describe which carriers and flight were handled in this log
g_my_header_data-carrid = 'AB'. "#EC NOTEXT
g_my_header_data-txt_carrid = 'Airways AB'. "#EC NOTEXT
g_my_header_data-connid = '0003'."#EC NOTEXT
g_my_header_data-txt_connid = 'Hamburg - New York'(001).
append g_my_header_data.
g_my_header_data-carrid = 'XY'. "#EC NOTEXT
g_my_header_data-txt_carrid = 'XY Lines'. "#EC NOTEXT
g_my_header_data-connid = '0002'."#EC NOTEXT
g_my_header_data-txt_connid = 'Walldorf - Tokio'(002).
append g_my_header_data.
g_my_header_data-carrid = 'ZZ'. "#EC NOTEXT
g_my_header_data-txt_carrid = 'ZZ Wings'. "#EC NOTEXT
g_my_header_data-connid = '0014'."#EC NOTEXT
g_my_header_data-txt_connid = 'Paris - Frankfurt'(003).
append g_my_header_data.
endform.
*--------------------------------------------------------------------
* FORM log_message_create
*--------------------------------------------------------------------
form log_message_create
using
i_log_handle type balloghndl.
data:
l_s_msg type bal_s_msg,
l_s_par type bal_s_par,
l_s_my_data type bal_s_ex06.
* create a message
* 327(BL): "&1 customers were allowed to fly for free (see detail)"
clear l_s_msg.
l_s_msg-msgty = 'E'.
l_s_msg-msgid = 'BL'.
l_s_msg-msgno = '327'.
l_s_msg-msgv1 = '3'.
* define callback routine
l_s_msg-params-callback-userexitp = sy-repid.
l_s_msg-params-callback-userexitf = 'CALLBACK_MSG_DETAIL'.
l_s_msg-params-callback-userexitt = const_callback_form.
* define an identifer. This is used to establish the link between
* the message and its additional data
add 1 to g_identifier.
* put his identifier into the parameters of the message
l_s_par-parname = const_name_msg_ident.
l_s_par-parvalue = g_identifier.
append l_s_par to l_s_msg-params-t_par.
* create the message
call function 'BAL_LOG_MSG_ADD'
exporting
i_log_handle = i_log_handle
i_s_msg = l_s_msg
exceptions
others = 1.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
* we want to store information for this message about the customers
* which were allowed to fly for free:
g_my_message_data-identifier = g_identifier.
l_s_my_data-id = '00000002'.
l_s_my_data-txt_id = 'Peter Smith'. "#EC NOTEXT
append l_s_my_data to g_my_message_data-t_my_data.
l_s_my_data-id = '00000013'.
l_s_my_data-txt_id = 'Paula Jones'. "#EC NOTEXT
append l_s_my_data to g_my_message_data-t_my_data.
l_s_my_data-id = '00001345'.
l_s_my_data-txt_id = 'Jane Meyer'. "#EC NOTEXT
append l_s_my_data to g_my_message_data-t_my_data.
append g_my_message_data.
endform.
*--------------------------------------------------------------------
* FORM log_save
*--------------------------------------------------------------------
form log_save
using
i_log_handle type balloghndl.
data:
l_t_log_handle type bal_t_logh,
l_s_new_lognumber type bal_s_lgnm,
l_t_new_lognumbers type bal_t_lgnm.
* save this log
insert i_log_handle into table l_t_log_handle.
call function 'BAL_DB_SAVE'
exporting
i_t_log_handle = l_t_log_handle
importing
e_new_lognumbers = l_t_new_lognumbers
exceptions
others = 1.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
* find out the lognumber of this saved log
read table l_t_new_lognumbers into l_s_new_lognumber
with key log_handle = i_log_handle.
check sy-subrc = 0.
g_lognumber = l_s_new_lognumber-lognumber.
* also save our own, complex data:
export g_my_header_data g_my_message_data
to database bal_indx(al)
id g_lognumber.
endform.
***********************************************************************
************** FORMS FOR DISPLAY OF THE LOG **************************
***********************************************************************
*--------------------------------------------------------------------
* FORM log_display
*--------------------------------------------------------------------
form log_display.
data:
l_s_log_filter type bal_s_lfil,
l_s_obj type bal_s_obj,
l_s_extn type bal_s_extn,
l_t_log_header type balhdr_t.
* create filter to search for this log on db
clear l_s_log_filter-object.
clear l_s_obj.
l_s_obj-sign = 'I'.
l_s_obj-option = 'EQ'.
l_s_obj-low = const_example_object.
append l_s_obj to l_s_log_filter-object.
clear l_s_extn.
l_s_extn-sign = 'I'.
l_s_extn-option = 'EQ'.
l_s_extn-low = const_example_extnumber.
append l_s_extn to l_s_log_filter-extnumber.
* search for this log
call function 'BAL_DB_SEARCH'
exporting
i_s_log_filter = l_s_log_filter
importing
e_t_log_header = l_t_log_header
exceptions
others = 1.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
* load these messages into memory
call function 'BAL_DB_LOAD'
exporting
i_t_log_header = l_t_log_header
exceptions
others = 1.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
* show this log:
* - we do not specify the display profile I_DISPLAY_PROFILE since
* we want to use the standard profile
* - we do not specify any filter (like I_S_LOG_FILTER, ...,
* I_T_MSG_HANDLE) since we want to display all messages available
call function 'BAL_DSP_LOG_DISPLAY'
* EXPORTING
* I_S_LOG_FILTER =
* I_T_LOG_CONTEXT_FILTER =
* I_S_MSG_FILTER =
* I_T_MSG_CONTEXT_FILTER =
* I_T_LOG_HANDLE =
* I_T_MSG_HANDLE =
* I_S_DISPLAY_PROFILE =
exceptions
others = 1.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endform.
*--------------------------------------------------------------------
* FORM CALLBACK_LOG_DETAIL
*--------------------------------------------------------------------
form callback_log_detail "#EC CALLED
tables
i_params structure spar.
* load my specififc data from database
perform load_my_data
tables
i_params.
* display header data
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_structure_name = 'BAL_S_EX05'
i_screen_start_column = 1
i_screen_start_line = 1
i_screen_end_column = 80
i_screen_end_line = 10
tables
t_outtab = g_my_header_data
exceptions
others = 1.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endform.
*--------------------------------------------------------------------
* FORM CALLBACK_MSG_DETAIL
*--------------------------------------------------------------------
form callback_msg_detail "#EC CALLED
tables
i_params structure spar.
data:
l_my_message_data type bal_s_ex06 occurs 0.
* load my specififc data from database
perform load_my_data
tables
i_params.
* find out the identifier for this message
read table i_params with key param = const_name_msg_ident.
check sy-subrc = 0.
g_identifier = i_params-value.
* search for those entries which belong to thgis message
read table g_my_message_data with key identifier = g_identifier.
check sy-subrc = 0.
l_my_message_data = g_my_message_data-t_my_data.
* display header data
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_structure_name = 'BAL_S_EX06'
i_screen_start_column = 1
i_screen_start_line = 1
i_screen_end_column = 80
i_screen_end_line = 10
tables
t_outtab = l_my_message_data
exceptions
others = 1.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endform.
*--------------------------------------------------------------------
* FORM LOAD_MY_DATA
*--------------------------------------------------------------------
form load_my_data
tables
i_params structure spar.
data:
l_lognumber type balhdr-lognumber.
* find out the log number of this log which is displayed
* (this number is automatically added by the display module)
read table i_params with key param = bal_param_lognumber.
if sy-subrc = 0.
l_lognumber = i_params-value.
endif.
* when number has changed, load these data
if g_lognumber ne l_lognumber.
g_lognumber = l_lognumber.
import g_my_header_data g_my_message_data
from database bal_indx(al)
id g_lognumber.
if sy-subrc ne 0.
clear:
g_my_header_data[],
g_my_message_data[].
endif.
endif.
endform.
***********************************************************************
************** FORMS FOR DELETION OF THE LOG *************************
***********************************************************************
*--------------------------------------------------------------------
* FORM log_delete
*--------------------------------------------------------------------
form log_delete.
data:
l_s_log_filter type bal_s_lfil,
l_s_obj type bal_s_obj,
l_s_extn type bal_s_extn,
l_t_log_header type balhdr_t.
* create filter to search for this log on db
clear l_s_log_filter-object.
clear l_s_obj.
l_s_obj-sign = 'I'.
l_s_obj-option = 'EQ'.
l_s_obj-low = const_example_object.
append l_s_obj to l_s_log_filter-object.
clear l_s_extn.
l_s_extn-sign = 'I'.
l_s_extn-option = 'EQ'.
l_s_extn-low = const_example_extnumber.
append l_s_extn to l_s_log_filter-extnumber.
* search for this log
call function 'BAL_DB_SEARCH'
exporting
i_s_log_filter = l_s_log_filter
importing
e_t_log_header = l_t_log_header
exceptions
others = 1.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
* delete these logs
call function 'BAL_DB_DELETE'
exporting
i_t_logs_to_delete = l_t_log_header
exceptions
others = 1.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endform.
如何使用应用日志(Application Log)相关推荐
- 【转】如何使用应用日志(Application Log)
SAP的应用日志(Application Log)是用于创建,保存和分析系统消息的工具. 相关TCODE: SLG0: Creation of Object and Sub object SLG1: ...
- 故障:在 Application Log 中出现 ID33152 的 Backup Exec 错误日志
1.故障现象: 定检一台 Windows Server 2008 的 Symantec Backup Exec 服务器,如果重启该服务器,在 Windows Event Viewer 的 Applic ...
- Android中日志打印 Log的使用
文章目录 Log等级划分 Log使用规范 Android Studio中log使用 Logcat中选择筛选条件 Log信息颜色设置 Log信息说明 写一份便于使用的Log辅助类 Log等级划分 Log ...
- windows日志分析-Log Parser等工具使用
Windows 主要有以下三类日志记录系统事件:应用程序日志.系统日志和安全日志 系统日志:%SystemRoot%\System32\Winevt\Logs\System.evtx 记录操作系统组件 ...
- python logging模块-写日志、log回滚
python包/模块,专栏总目录: 1.python自定义模块 2.python模块调用顺序 3.python logging模块 4.python定义跨模块的全局变量 1.logging模块简介 l ...
- Android的日志工具Log
Android的日志工具类是Log(android.util.Log),这个类中提供了如下5个方法来供我们打印日志. Log.v() 用于打印那些最为琐碎的.意义最小的日志信息.对应级别verbose ...
- mysql错误日志/var/log/mariadb/mariadb.log,二进制日志
mariadb-日志 IT_luo关注0人评论65人阅读2018-10-15 08:59:03 mariadb日志 mariadb日志:1.查询日志:query log:2.慢查询日志:slow qu ...
- linuxmessage日志消失_某工的centos7 启动了rsyslog之后,日志/var/log/messages等都不产生日志了,都是空的。求大神解决!...
之前一直有日志生成的,正常运行,自从前几天搞了下好像重启了下rsyslog ,最后一次轮替日志之后,/var/log/message, /var/log/secure等都不记录了,并且都是空文件. 求 ...
- golang日志服务器_日志系统 | log/syslog (log) – Go 中文开发手册 - Break易站
Go 中文开发手册 日志系统 | log/syslog (log) - Go 中文开发手册 import "log/syslog"概述索引示例 概述 软件包系统日志为系统日志服务提 ...
最新文章
- python基础之常用模块
- magento工具PHP语言,Magento2建立中文翻译语言包
- php strtotime 和 date 日期操作
- 掌握这 11 个方法论,搞定一场完美技术面试!
- 数据库设计注意事项和原则
- boot sprint 项目结构_Spring Boot 项目结构
- 金山词霸”屏幕取词技术揭密(讨论稿)
- Git:查看所有远程分支以及同步远程代码
- vi打开GBK编码文件乱码问题
- wingdings字体符号在哪_Wingdings特殊字符及符號對照表 | 學步園
- 一加nfc门禁卡录入_一加手机NFC门禁卡模拟加密卡教程(需root)
- logisim 快速加法器设计实验报告_华中科技大学数字逻辑实验
- torch+cuda gpu并行计算
- python count函数代码_python中count函数简单用法
- [React Native Development] Camping Spots Finder应用程序用户界面克隆第一部分-地图视图用户界面...
- 我是如何学习 Linux 的?
- Access数据库实战(二): Nz函数
- 职高计算机基础工作计划,2019职高教师个人工作计划
- umi 解决找不到antd组件库中组件的路径问题 filePath not found of antd/es/float-button
- AP报名截止时间近在咫尺,2023年AP考试时间表已公布
热门文章
- 产品新人的10字生存手册
- [心得分享] 产品规划思考
- Tracer Druid 记录sql 以及参数
- Koa与Node.js开发实战(1)——Koa安装搭建(视频演示)
- 网络部署加实验步骤( 续)
- Python PhantomJS 爬虫 示例
- 11g Active DataGuard初探
- 在虚拟机中安装gentoo简化步骤(基于官方手册)
- SoaBox 1.1.6 GA 发布,SOA 模拟环境
- 2008年CCNA第三学期第一单元中文题目(2008-12-21 18:30:01