`
guanhuaing
  • 浏览: 1196340 次
文章分类
社区版块
存档分类
最新评论

如何使用应用日志(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.

分享到:
评论

相关推荐

    HANA_ABAP_ApplicationLog_OrphanRecords.txt

    HANA SQL Statement - HANA_ABAP_ApplicationLog_OrphanRecords

    erlang日志应用log4erl(非sasl)

    &gt; application:start(log4erl). 3- Create a configuration file and load it using log4erl:conf(File) &gt; log4erl:conf("priv/log4erl.conf"). 4- Alternatevly, you can create loggers & add appenders to them...

    log4 DELPHI 日志

    日志组件log4delphi与log4j、log4cpp如出一辙 1.安装:log4Delphi无需安装,直接解压包解压后放入任意目录(我的目录是:'D:/3rdlib/delphi/log4delphi-0.7)即可。 2.使用:在工程文件中引用解压包中src目录下...

    运用log4net将日志信息保存到Oracle数据库

    使用说明 一:下载log4net.dll 将log4net.dll拷贝到bin下面,并添加对它的引用 二:在数据库里面创建表Log create table LOG ( LOGDATE VARCHAR2(20), LOG_LEVEL VARCHAR2(255), LOGGER VARCHAR2(255), MESSAGE ...

    log4pb, pb的日志组件, 后台线程记录日志

    // Description: pb日志组件,把log4pb.pbd, callback.pbd加入到开发的libary列表中 // 1. log4pb调用演示例子, 思想仿log4j // 2. 集成对象到application, // 3. 组件文件: log4pb90.pdb + callback.pbd, // 4. ...

    Java应用日志框架TNT4J.zip

    TNT4J是一个改进Log4J新的开源Java应用日志框架。用于应用程序活动的跟踪、相关性检查、诊断,可以跨多个应用程序,运行时,服务器,地理的位置。这个API是专门用以解决分布式,并发,多线程,多用户应用,包括活动...

    C#3.0使用EventLog类写Windows事件日志的方法

    本文实例讲述了C#3.0使用EventLog类写Windows事件日志的方法。...下面是一个使用EventLog类向应用程序(Application)写入日志的例子,日志类型使用EventLogEntryType枚举类型指定。 EventLog log = new

    诊断SQLSERVER问题常用的日志概述及使用

    SQLSERVER也会把自己的一些概要信息同时记录在Windows的应用程序日志里Application Log而Windows日志本身又能够反映操作系统的健康情况,是否有任何软件或硬件的异常。 如果Windows本身不能正常工作,SQLSERVER的...

    log-parser:Java Log Parser应用程序

    要运行该应用程序,首先在您的本地主机上创建一个名为“ log_parser”的mysql表,然后创建一个用户“ log_parser_application”。 运行installDB.sql创建表并运行以下命令: 使用accesslog文件: java -jar parser....

    c#.NET中日志信息写入Windows日志中解决方案

     在Windows2000及以上操作系统中,有一个Windows日志系统,它包括应用程序(Application)事件日志、系统(System)日志和安全(Security)日志,事件日志也可以是自定义日志。在.net Framework中也提供了相应的类...

    ApplicationInsights-dotnet-logging:.NET日志适配器

    日志Application Insights NLog目标nuget包在您的web.config中添加了ApplicationInsights目标。 如果您的应用程序没有web.config,则也可以手动对其进行配置。 使用NLog.config配置ApplicationInsightsTarget : &lt...

    log-searcher-indexer:原型日志搜索器和索引器应用程序

    此应用程序的目的是展示将​​应用程序日志内容写入数据库(SQL/NoSQL,尽管 NoSQL 最适合写入密集型应用程序)并在需要时将其读回的能力。 这个应用程序基本上是一个简单的 Web 应用程序,它有一个非常简单的前端...

    logstashHTTP:用于log4js-node的Logstash HTTP附加程序

    application string (可选)-用于标识应用程序的日志 logChannel string (可选)-也用于标识应用程序的日志[但以更具体的方式] logType string (可选)-用于logstash数据中的type字段 timeout integer (可选,...

    log_weasel:具有共享事务ID的Instrument Rails和Resque可以跟踪跨应用程序和应用程序实例的工作单元的执行

    如果您正在使用类的系统来管理许多应用程序和应用程序实例中的日志文件,这将特别方便。 安装 将log_weasel添加到您的Gemfile中: gem 'log_weasel' 使用捆绑程序安装它: bundle install 滑轨3 对于Rails 3,...

    .net log4的详细用法

    本人开始接触.net 日志,如有不对之处还请多多指教! lLog4Net是用来记录日志的,可以将程序运行过程中的信息输出到一些地方...l配置Log4Net环境•新建一个WebApplication,添加一个“应用程序配置文件”(App.config

    cloudtrail-log-analytics:使用Amazon Elasticsearch Service的Cloudtrail Log Analytics-AWS无服务器应用程序

    该无服务器AWS应用程序将帮助您使用Amazon Elasticsearch Service分析AWS CloudTrail日志。 每当将CloudTrail日志文件写入s3时,该应用程序都会创建CloudTrail线索,将日志传递设置为它创建的s3存储桶,并配置SNS...

    SpringMVCDemo:与 Hibernate、Junit 和 log4j 集成的 Spring MVC 应用程序

    此应用程序演示了使用 Spring MVC 和其他技术,如Hibernate、junit 和 log4j。 此应用程序还演示了使用基于 java 的配置,而不是使用 xml 进行配置。 下载应用程序更改 SpringMVCDemo/SpringMVC/src/main/...

    app-application-logger:一个小型的独立Windows应用程序,用于记录正在使用的应用程序

    Application Logger是一个小型的独立Windows应用程序,可随时记录当前用户正在运行的应用程序,并在用户每次更改焦点时将它们添加到日志文件中。 我之所以创建它,是因为我想记录我一直在使用的所有应用程序以及...

    workout-log:WorkoutLog Web应用程序

    使用WL,您可以: 创建练习进行锻炼添加身体测量(您也可以添加照片) 查看锻炼和测量日志看天气里面有什么该项目基于项目,并使用以下软件包: ()Log4g2 安装该项目是使用Maven创建的,因此您只需要将其导入到...

    captains_log:基础架构变更日志工具

    Captain's Log是一个Rails应用程序,它提供了一个集中记录基础结构更改的地方。 发展 Ruby-2.0.0-p353 Rails 4.0.1 bundle install rake db:migrate rake db:test:prepare && rake db:migrate RAILS_ENV=test ...

Global site tag (gtag.js) - Google Analytics