JBoss Access log的配置详解

在做WEB应用时,有时候希望能够记录用户的访问,分析访问用户的地域以及用户访问行为,JBoss提供了一种方式能够很方便的记录用户的访问日志,但是默认情况下这个功能是没有启用的,下面讲述如何启用这个功能。

  1. 修改${JBOSS_HOME}/server/defaul/deploy/jbossweb.sar/server.xml找到如下代码:

    Xml代码  收藏代码

    1.  <Valve className="org.apache.catalina.valves.AccessLogValve"   
    2.               prefix="localhost_access_log." suffix=".log"   
    3. pattern="%h %l %u %t %r %s %b" directory="${jboss.server.home.dir}/log"  
    4.                resolveHosts="false" />  
     上述代码默认情况下是注释的,将注释去掉,就打开了访问日志记录阀。
  2. 参数/选项说明:

    className: 实现的java类名,必须设置成org.apache.catalina.valves.AccessLogValve;
    directory: 存放日志文件的目录;
    pattern:    需要记录的日志信息的格式布局,如果是”common”或者”combined”,说明是使用的标准记录格式,也有自定义的格式,下面会详细说明;
    prefix:    日志文件名的前缀,如果没有指定,缺省值是”access_log.;(要注意后面有个小点);
    resolveHosts: 将远端主机的IP通过DNS查询转换成主机名,设为true。如果为false,忽略DNS查询,报告远端主机的IP地址;
    sufix:    日志文件的后缀名。(sufix=”.log”);也需要注意有个小点;
    rotatable: 缺省值为true,决定日志是否要翻转,如果为false则永不翻转,并且忽略fileDateFormat,谨慎使用。
    condition: 打开条件日志
    fileDateFormat:允许在日志文件名称中使用定制的日期格式。日志的格式也决定了日志文件翻转的频率。

                          如果想每小时翻转一次,可以定义为“yyyy-MM-dd.HH”;

 

pattern的详细说明

 

    %a    远端IP
    %A 本地IP
    %b    发送的字节数,不包含HTTP头,如果为0,使用”-”
    %B    发送的字节数,不包含HTTP头
    %h    远端主机名(如果resolveHosts=false),远端的IP
    %H    请求协议
    %l    从identd返回的远端逻辑用户名,总是返回’-’
    %m    请求的方法
    %p    收到请求的本地端口号
    %q    查询字符串
    %r    请求的第一行
    %s 响应的状态码
    %S    用户的sessionID
    %t    日志和时间,使用通常的log格式
    %u    认证以后的远端用户(如果存在的话,否则为’-’)
    %U    请求的URI路径
    %v    本地服务器的名称
    %D 处理请求的时间,以毫秒为单位
    %T    处理请求的时间,以秒为单位

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
deploy/jbossweb-tomcat55.sar/server.xml <Valve className="org.apache.catalina.valves.FastCommonAccessLogValve" prefix="access_log." suffix=".log" pattern="%h %t %r %s %D" directory="${jboss.server.home.dir}/../output/logs" resolveHosts="false" /> http://tomcat.apache.org/tomcat-5.5-doc/config/valve.html pattern配置: %a - Remote IP address %A - Local IP address %b - Bytes sent, excluding HTTP headers, or '-' if zero %B - Bytes sent, excluding HTTP headers %h - Remote host name (or IP address if resolveHosts is false) %H - Request protocol %l - Remote logical username from identd (always returns '-') %m - Request method (GET, POST, etc.) %p - Local port on which this request was received %q - Query string (prepended with a '?' if it exists) %r - First line of the request (method and request URI) %s - HTTP status code of the response %S - User session ID %t - Date and time, in Common Log Format %u - Remote user that was authenticated (if any), else '-' %U - Requested URL path %v - Local server name %D - Time taken to process the request, in millis %T - Time taken to process the request, in seconds %I - current request thread name (can compare later with stacktraces) There is also support to write information from the cookie, incoming header, outgoing response headers, the Session or something else in the ServletRequest. It is modeled after the apache syntax: %{xxx}i for incoming request headers %{xxx}o for outgoing response headers %{xxx}c for a specific request cookie %{xxx}r xxx is an attribute in the ServletRequest %{xxx}s xxx is an attribute in the HttpSession The shorthand pattern name common (which is also the default) corresponds to '%h %l %u %t "%r" %s %b'.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值