WebSphere 自定义访问日志

发布于 2024-12-01 18:23:15 字数 214 浏览 1 评论 0 原文

是否可以自定义 WebSphere 访问日志(通过代码或配置)?我在控制台中看到 WebSphere 支持 NCSA 通用格式或组合格式,但没有自定义格式的选项。

我希望自定义访问日志以包含有助于调试的附加信息,例如代理、vip、LB、响应时间等。

如果不可能,我愿意接受开箱即用的想法。关键是我正在尝试获取记录的附加信息以进行调试。 log4j 是一个选项吗?也许自定义跟踪日志?

Is it possible to customize the WebSphere access logs (through code or configuration)? I see in the Console that WebSphere supports either NCSA common or combined formats, but there's no option for custom formats.

I was hoping to customize the access logs to include additional info that will assist in debugging such as proxy, vip, LB, response time, etc.

If it isn't possible, I'm open for out of the box ideas. The key is I'm trying to get additional info logged for debugging. Is log4j an option? Maybe custom trace logs?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

昇り龍 2024-12-08 18:23:15

您可以做的一件事是 在 WAS 中设置一个 Web 服务器 IBM 有一个 HTTP 服务器,它只包装了 Apache,这可能会给您带来更少的麻烦,或者您可以使用 Apache, IIS等

配置完成后,您应该能够安装所需的 Apache 模块来处理自定义日志记录。其工作原理是网络服务器充当实际应用程序服务器的前端,并将请求传递给它。

One thing you could do is set up a webserver in WAS IBM has a HTTP server which just wraps Apache which will probably give you less headaches, or you can use Apache, IIS,etc.

Once configured you should be able to install required Apache modules to handle custom logging. How this works is the webserver acts as a front end to your actual application server, and passes requests to it.

若无相欠,怎会相见 2024-12-08 18:23:15

自定义访问日志适用于 WAS 8.0.0.2 及更高版本。

当您愿意接受新想法时,您可以激活 servlet 的请求度量工具,如博客条目

可以在管理控制台的“监控和调整”>“管理控制台”下启用请求指标。请求指标。无需重新启动服务器即可让请求指标开始工作。

  1. 确保选中“为请求指标收集准备服务器”
  2. 为“要检测的组件”选择“自定义”,然后选择“Servlet”
  3. 将“跟踪级别”设置为“跳跃”
  4. 检查“标准日志”

为每个请求记录的信息都在此格式

[9/26/11 15:43:45:448 PDT] 00000027 PmiRmArmWrapp I PMRM0003I: parent:ver=1,ip=10.20.30.8,time=1317075586068,pid=32507,reqid=1,event=1 - current:ver=1,ip=10.20.30.8,time=1317075586068,pid=32507,reqid=1,event=1 type=URI detail=/swat/Sleep elapsed=1004

elapsed 字段是以毫秒为单位的响应时间。

Custom access log is available for WAS 8.0.0.2 onwards.

As you are open to new ideas, you may activate request metrics facility for servlet as explained in this blog entry

Request metrics can be enabled in the administrative console under Monitoring and Tuning > Request Metrics. The server does not need to be restarted for request metrics to start working.

  1. Ensure "Prepare Servers for Request metrics collection" is checked
  2. Select "Custom" for "Components to be instrumented" and select "Servlet"
  3. Set "Trace level" to "Hops"
  4. Check "Standard Logs"

The informattion logged for each request is in this format

[9/26/11 15:43:45:448 PDT] 00000027 PmiRmArmWrapp I PMRM0003I: parent:ver=1,ip=10.20.30.8,time=1317075586068,pid=32507,reqid=1,event=1 - current:ver=1,ip=10.20.30.8,time=1317075586068,pid=32507,reqid=1,event=1 type=URI detail=/swat/Sleep elapsed=1004

The elapsed field is the response time in milliseconds.

且行且努力 2024-12-08 18:23:15

一种实用的方法是创建您自己的自定义请求记录器实现。您可以使用 WAS 功能“全局 Web 容器侦听器”和标准 Servlet API ServletRequestListener 来执行此操作。

下面是一个伪示例:

import javax.servlet.ServletRequest;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpServletRequest;

public class HttpServletRequestRequestListener implements ServletRequestListener {

ThreadLocal<Long> threadLocal = new ThreadLocal<Long>(); 

@Override
public void requestDestroyed(ServletRequestEvent aArg0) {
    HttpServletRequest tHttpServletRequest = getHttpServletRequest(aArg0.getServletRequest());
    if(tHttpServletRequest != null){
        Long tStart = threadLocal.get();
        long tCallDelay = -1;
        if(tStart != null){
            tCallDelay = System.currentTimeMillis() - tStart.longValue();
        }
        //In this class I will log the request including cookies etc. 
        // in my own customized format...
        MyCustomLogger.log(tHttpServletRequest,tCallDelay);
    }

}

@Override
public void requestInitialized(ServletRequestEvent aArg0) {
    long tStart = System.currentTimeMillis();
    threadLocal.set(tStart);

}

private static HttpServletRequest getHttpServletRequest(ServletRequest aServletRequest) {
    if (aServletRequest instanceof HttpServletRequest) {
        return (HttpServletRequest) aServletRequest;
    }
    return null;
}

}

此外,在 webcontainer 自定义属性中,您应该使用listeners 属性指向您的侦听器。

以下是有关如何配置 Web 容器侦听器的更多信息:
http://pic.dhe.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=%2Fcom.ibm.websphere.base.doc%2Finfo%2Faes%2Fae%2Frweb_custom_props.html

One practical way is to create your own customized request logger implementation. You can perform this using the WAS feature "Global webcontainer listener" with a standard Servlet API ServletRequestListener.

Here is an pseudo example:

import javax.servlet.ServletRequest;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpServletRequest;

public class HttpServletRequestRequestListener implements ServletRequestListener {

ThreadLocal<Long> threadLocal = new ThreadLocal<Long>(); 

@Override
public void requestDestroyed(ServletRequestEvent aArg0) {
    HttpServletRequest tHttpServletRequest = getHttpServletRequest(aArg0.getServletRequest());
    if(tHttpServletRequest != null){
        Long tStart = threadLocal.get();
        long tCallDelay = -1;
        if(tStart != null){
            tCallDelay = System.currentTimeMillis() - tStart.longValue();
        }
        //In this class I will log the request including cookies etc. 
        // in my own customized format...
        MyCustomLogger.log(tHttpServletRequest,tCallDelay);
    }

}

@Override
public void requestInitialized(ServletRequestEvent aArg0) {
    long tStart = System.currentTimeMillis();
    threadLocal.set(tStart);

}

private static HttpServletRequest getHttpServletRequest(ServletRequest aServletRequest) {
    if (aServletRequest instanceof HttpServletRequest) {
        return (HttpServletRequest) aServletRequest;
    }
    return null;
}

}

Further, in the webcontainer custom properties, you should point to your listener using the listeners property.

Here is more information of how do configure a webcontainer listener:
http://pic.dhe.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=%2Fcom.ibm.websphere.base.doc%2Finfo%2Faes%2Fae%2Frweb_custom_props.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文