tomcat 和 jboss access log 日志输出详解

工作中nginx+jboss/tomcat反向代理集成,想打开后端jboss的access log,

配置在:/home/admin/wdetail/conf/tomcat-server.xml

开启日志将下面内容的注释去掉:

           <valve classname="org.apache.catalina.valves.AccessLogValve" <="" div="" style="word-wrap: break-word;">

                prefix="localhost_access_log." suffix=".log"

                pattern="common" directory="${jboss.server.home.dir}/log" 

                resolveHosts="false" />

pattern 项的修改,可以改变日志输出的内容。

该项值可以为: common 与 combined ,这两个预先设置好的格式对应的日志输出内容如下:

common 的值: %h %l %u %t %r %s %b

combined 的值: %h %l %u %t %r %s %b %{Referer}i %{User-Agent}i

pattern的格式也可以自定义:

<valve classname="org.apache.catalina.valves.AccessLogValve" <="" div="" style="word-wrap: break-word;">

                prefix="localhost_access_log." suffix=".log"

                pattern="%{X-Real-IP}i %a %l %u %D %t %r %s %b %{Referer}i %{User-Agent}i" directory="${jboss.server.home.dir}/../logs" resolveHosts="false" />

这里log的路径可以更改:directory="${jboss.apphome.dir}/logs"

jboss.apphome.dir这个变量必须要到jbossctl里去定义,加到JAVA_OPTS里面去:

JAVA_OPTS="${JAVA_OPTS} -Djboss.apphome.dir=$BASE_HOME"

碰到问题,jboss记录的ip不是真实ip,需要在nginx上配置下:

           proxy_redirect  off;

            proxy_set_header Host            $host;

           proxy_set_header X-Real-IP       $remote_addr;

            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

pattern的详细说明

 http://tomcat.apache.org/tomcat-6.0-doc/config/valve.html

    %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    处理请求的时间,以秒为单位

参数/选项说明:

    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”;


特别说明:尊重作者的劳动成果,转载请注明出处哦~~~http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt179
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 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、付费专栏及课程。

余额充值