开启JBoss7/WildFly的access_log功能

本文详细介绍了如何在JBossAs7和WildFly8中开启访问日志功能,包括配置文件修改步骤及日志文件生成路径。提供了两种配置示例,并对比了日志输出格式,帮助开发者了解如何根据需求选择合适的日志格式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言

对于一个网站来说,访问日志,即access_log,对网站来说是一项很重要的功能。利用它,我们可以统计出很多有用的信息,从而给网站的运维带来方便,所以基本上每个网站都会开启这件功能。

JBoss As 7配置

在默认的情况下,JBoss7.1是没有开启access_log的,如果要开启这项功能,就需要修改$JBOSS_HOME\standalone\configuration\standalone.xml(domain.xml)这个文件,相关的修改内容如下所示:

<subsystem xmlns="urn:jboss:domain:web:1.0"default-virtual-server="default-host">
<connector name="http"scheme="http" protocol="HTTP/1.1" socket-binding="http"/>
<virtual-server name="default-host" enable-welcome-root="true">
<alias name="localhost"/>
<alias name="example.com"/>
<access-log/>
</virtual-server>
</subsystem>

当完成上面的配置并重启服务器后,你就可以访问一下你的网站,然后你就会在$JBOSS_HOME\standalone\log\default-host目录下看到一个名为access_log.2012-02-24的文件,它就是你所需要的访问日志了。

WildFly 8 配置

WildFly开启access_log的方法和JBoss 7 类似,也是找到相对应的web容器添加上配置就可以了,只不过二者使用的容器不相同,而且WildFly中必须指定log的存放目录。


<subsystem xmlns="urn:jboss:domain:undertow:1.0">
<buffer-caches>
<buffer-cache name="default" buffer-size="1024" buffers-per-region="1024" max-regions="10"/>
</buffer-caches>
<server name="default-server">
<http-listener name="default" socket-binding="http"/>
<host name="default-host" alias="localhost">
<location name="/" handler="welcome-content"/>
<filter-ref name="server-header"/>
<filter-ref name="x-powered-by-header"/>
<access-log pattern="common" directory="${jboss.home.dir}/standalone/log" prefix="access" />
</host>
</server>
<servlet-container name="default" default-buffer-cache="default" stack-trace-on-error="local-only">
<jsp-config/>
</servlet-container>
<handlers>
<file name="welcome-content" path="${jboss.home.dir}/welcome-content" directory-listing="true"/>
</handlers>
<filters>
<response-header name="server-header" header-name="Server" header-value="Wildfly 8"/>
<response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow 1"/>
</filters>
</subsystem>

如上,添加红色标记一行,即可开启WildFly 8的access_log功能,重启服务器,访问ip:8080即可在JBOSS_HOME/standalone/log目录下生成access.log

其中

prefix指定log文件的前缀名即文件名

pattern指定日志的格式

pattern可以设置成两种方式,第一种是pattern="common",第二种是pattern="combined"

以下是笔者测试的两种格式的日志输出,访问localhost:8080

common格式的日志输出如下:


combined格式的日志输出如下:


可以看出,第二种格式的日志输出相对具体,而实际开发过程中开启哪种格式的access_log要根据需求来确定就可以了。

结束语

开启access_log的配置到此结束,若有问题,请参考以下资料,谢谢!

参考资料

https://issues.jboss.org/browse/WFLY-1721

http://hi.baidu.com/saiv000/item/9ed9779aa1b1a2dc1f4271ea

http://hooray520.iteye.com/blog/1335156

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、付费专栏及课程。

余额充值