简体   繁体   中英

WebSphere custom access logs

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?

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM