技术开发 频道

解读 WebSphere Application Server 跟踪文件

    如何启用跟踪

    通过管理控制台选择 Troubleshooting => Logs and Trace => [ServerName] => Diagnostic Trace Service,可以启用 WebSphere Application Server 跟踪功能。(对于 V6.0 及更新版本的用户,Change Log Detail Levels 链接是实际设置跟踪字符串的位置。)
图 1. Diagnostic Trace Service

图 2. Change Log Detail Levels


    在 Configuration 选项卡下指定跟踪设置时,将需要重新启动服务器,以使跟踪生效。不过,在 Runtime 选项卡下启用跟踪时,将立即生效(对于跟踪生产环境之类的环境非常有用,因为这种环境很难接受服务器重启)。不过,务必记住,除非选中了 Save runtime changes to configuration as well 框,否则服务器重新启动后将丢失运行时设置。另外,运行时跟踪仅报告当前系统信息;如果服务器已经存在问题,启用运行时跟踪将不会报告导致问题的原因,而仅会报告当前操作为何失败。因此,IBM Support 建议在 Configuration 选项卡下进行跟踪设置,以便能查看服务器重启情况,确定问题的根源。

    Diagnostic Trace Service 面板(图 1)还允许指定除跟踪字符串之外的其他跟踪选项,如跟踪文件名、最大文件大小、历史备份文件数量以及跟踪格式。“Basic”跟踪格式是 WebSphere Application Server 支持团队的首选跟踪格式——同时也是缺省跟踪格式。Maximum File Size 和 Maximum Number of Historical Files 对于确保所捕获的跟踪信息不会被覆盖或丢失非常重要。在缺省情况下,文件大小设置为 20 MB,备份文件数量设置为一个。这意味着,当 trace.log 文件大小达到 20 MB 时,将创建新的 trace.log,并将之前的 trace.log 重命名为 trace_<date>.log,其中 <date> 是跟踪中的最后一个条目的日期和时间。不过,当新 trace.log 的大小再次达到 20 MB 时,会和前面一样创建新的跟踪文件,但之前的 trace_<date>.log 将被删除。因此,在出现复杂或费时的问题时,请务必确保 Number of Historical Files 和 Maximum File Size 足够大。Historical Files 的最大值为 20。WebSphere Application Server 支持团队喜欢将 Maximum File Size 保持在不大于 50 MB 的大小,因为文件大小太大将更难于加载和阅读。

    WebSphere Application Server 信息中心提供了每个 Diagnostic Trace Service 设置及其描述的完整列表。

    如果不能访问管理控制台,还可以通过 wsadmin 实用工具启用跟踪功能。可使用以下命令来在配置上启用跟踪功能(此示例将跟踪字符串设置为 com.ibm.ws.*=all=enabled):

set server [$AdminConfig getid /Cell:<mycell>/Node:<mynode>/Server:<myserver>/] set tc [$AdminConfig list TraceService $server] $AdminConfig modify $tc {{startupTraceSpecification com.ibm.ws.*=all=enabled}} $AdminConfig save

    同样,这仅在服务器重新启动后生效。要通过 wsadmin 启用运行时跟踪,请使用以下命令:

set ts [$AdminControl queryNames type=TraceService,node=<mynode>,process=<myserver>,*] $AdminControl setAttribute $ts traceSpecification com.ibm.ws.*=all=enabled

    信息中心提供了有关通过 wsadmin 工具启用跟踪功能的更多信息。

    在不能访问管理控制台和 wsadmin 实用工具的情况下,则可以通过直接编辑相关服务器的 server.xml 文件来启用跟踪功能,但仅在没有其他选项可用的情况下才建议采用此方法,且仅在下次服务器启动之后才生效(没有运行时跟踪功能)。不正确地编辑文件可能导致服务器无法重新启动,因此强烈建议在编辑此文件前进行备份。还要记住,如果由于自动同步流程导致从部署管理器下推一个新副本,则可能最终会覆盖此 server.xml 文件。要编辑的具体 xml 标记如下:

<services xmi:type="traceservice:TraceService" xmi:id="TraceService_1149168481635" enable="true" startupTraceSpecification="*=info" traceOutputType="SPECIFIED_FILE" traceFormat="BASIC"> <traceLog xmi:id="TraceLog_1149168481635" fileName="${SERVER_LOG_ROOT}/trace.log" rolloverSize="20" maxNumberOfBackupFiles="1"/>

    有关更多详细信息,请参见 how to setup a WebSphere Application Server trace。

    跟踪 Header

SystemOut.log 和 trace.log 文件顶部的 Header 包含关于生成日志的服务器的重要信息。

************ Start Display Current Environment ************
WebSphere Platform 6.0 [ND 6.0.2.15 cf150636.04] running with process
name carterfinleyNode02Cell\carterfinleyNode01\server1 and process id
2744
Host Operating System is Windows XP, version 5.1
Java version = J2RE 1.4.2 IBM Windows 32 build cn142ifx-20061121 (ifix
112270: SR6 + 111682 + 111872 + 110979) (JIT enabled: jitc), Java
Compiler = jitc, Java VM name = Classic VM
was.install.root = C:\WebSphere60
user.install.root = C:\WebSphere60\profiles\AppSrv01
Java Home = C:\WebSphere60\java\jre
ws.ext.dirs = C:\WebSphere60/java/lib;C:\WebSphere60\profiles\AppSrv01/classes;C:\Web
Sphere60/classes;C:\WebSphere60/lib;C:\WebSphere60/installedChannels;C:
\WebSphere60/lib/ext;C:\WebSphere60/web/help;C:\WebSphere60/deploytool/
itp/plugins/com.ibm.etools.ejbdeploy/runtime
Classpath = C:\WebSphere60\profiles\AppSrv01/properties;C:\WebSphere60/properties;C
:\WebSphere60/lib/bootstrap.jar;C:\WebSphere60/lib/j2ee.jar;C:\WebSpher
e60/lib/lmproxy.jar;C:\WebSphere60/lib/urlprotocols.jar
Java Library path = C:\WebSphere60\java\bin;.;C:\WINNT\system32;C:\WINNT;C:\WebSphere60
\bin;C:\WebSphere60\java\bin;C:\WebSphere60\java\jre\bin;C:\WebSphere51\IBM
\WebSphere_MQ\Java\lib;C:\PROGRAM FILES\THINKPAD\UTILITIES;C:\WINNT\sys
tem32;C:\WINNT;C:\WINNT\System32\Wbem;(etc...)
Current trace specification = *=info:com.ibm.ws.security.*=all
************* End Display Current Environment *************


    在每次服务器启动时也会生成此 Header。通过此 Header,可以看到具体的 WebSphere Application Server 级别和 Java™ 版本、计算单元名称、节点名称、服务器名称以及进程 ID。

    此外,还可以看到类路径和 Java 库路径以及 WebSphere Application Server 变量 was.install.root 和 user.install.root。从跟踪角度而言,Header 中最重要的部分是最后一行,其中显示了当前所使用的跟踪字符串:

Current trace specification = *=info:com.ibm.ws.security.*=all

    跟踪输出格式

    所有可用 WebSphere Application Server 跟踪设置的实际跟踪输出格式都是一致的,信息中心对此进行了说明。其基本格式是:

[timestamp] <threadId> <className> <eventType> <methodName> <textmessage>

<methodName> 和 <textMessage> 参数都是可选的。以下是一个示例跟踪输出:

[2/5/07 13:13:49:457 EST] 0000000a ConfigFile > buildFileEntry() Entry
[2/5/07 13:13:49:457 EST] 0000000a ConfigFile 3 JAAS login configuration file:
C:\WebSphere60\profiles\AppSrv01/properties/wsjaas.conf singleLogInFile: false
[2/5/07 13:13:49:497 EST] 0000000a ConfigFile 3 JAAS login configuration file:
C:\WebSphere60\profiles\AppSrv01/properties/wsjaas.conf processed
[2/5/07 13:13:49:497 EST] 0000000a ConfigFile < buildFileEntry() Exit


    通过上面的示例跟踪输出,可以看到:

时间是东部时间 2007 年 2 月 5 日 13:13:49。
跟踪输出显示了 ID 为 000000a 的单线程流程的情况。
所执行的类名称是“ConfigFile”。
如果类名称大于 13 个字符,将仅显示前 13 个字符。

    以下是每个跟踪条目行及其提供的信息的详细说明:

[2/5/07 13:13:49:457 EST] 0000000a ConfigFile > buildFileEntry() Entry

ConfigFile.buildFileEntry() 方法在此时开始执行。

[2/5/07 13:13:49:457 EST] 0000000a ConfigFile 3 JAAS login configuration file:
C:\WebSphere60\profiles\AppSrv01/properties/wsjaas.conf singleLogInFile: false

buildFileEntry() 代码中的调试语句。

[2/5/07 13:13:49:497 EST] 0000000a ConfigFile 3 JAAS login configuration file:
C:\WebSphere60\profiles\AppSrv01/properties/wsjaas.conf processed

buildFileEntry() 代码中的调试语句。

[2/5/07 13:13:49:497 EST] 0000000a ConfigFile < buildFileEntry() Exit

ConfigFile.buildFileEntry() 方法已完成执行并退出。

并非所有 WebSphere Application Server 代码都将输出方法进入点与退出点及调试消息。

0
相关文章