weblogic8,在access.log首行加入
如 自定义类c_username
#....x-c_username
weblogic9,10,使用扩展日志格式设置 HTTP 访问日志
登录console-Servers-AdminServer(admin)-Logging-选择http-Advanced-
其中Format 选择Extended
Extended Logging Format Fields :x-c_usernamedate time cs-method cs-uri sc-status bytes cs(Referer) cs(User-Agent) cs(cookie)
代码实现:
import weblogic.servlet.logging.*;
public class c_username
implements CustomELFLogger
{
public c_username()
{
}
public void logField(HttpAccountingInfo httpaccountinginfo, FormatStringBuffer formatstringbuffer)
{
formatstringbuffer.appendValueOrDash(httpaccountinginfo.getRemoteUser());
}
}
参考:
weblogic.servlet.logging
Interface CustomELFLogger
This is an interface which allows customers to add custom information to the ExtendedLogFormat. They will be responsible for implementing logField(HttpAccountingInfo metrics) method. ELF allows users to specify fields to be logged with each http request. One of these #Fields is an application specific field in the form of x-SOMEFIELDNAME WLS expects a fully qualified classname as the argument for this field and attempts to instantiate an instance of this class. Customers are responsible for following formatting guidlines of the specification. For example if they use one class to return two fields then they need to delimit them via a tab See: http://www.w3.org/TR/WD-logfile-960221.html for the specification Also they should use caution as this API provides them the opportunity to do anthying they want basically and they should not do something that will inordinantly SLOW the system down. Like looking something up in the DMBS, or doing signigicant IO or Networking
关键类:
weblogic.servlet.logging.LogManagerHttp
weblogic.servlet.logging.ELFLogger
weblogic.servlet.logging.CLFLoggerLogFormat
本文介绍如何在WebLogic中自定义HTTP访问日志格式,通过实现CustomELFLogger接口来加入自定义字段,如用户名,并详细解释了实现过程及所需遵循的规范。
1255

被折叠的 条评论
为什么被折叠?



