Enable Access Logs in JBoss 7 and tomcat--转

JBoss 7 is slightly different than earlier version JBoss 5 or 6. The procedure to enable access logs in JBoss 7 is also changed and you must be familiar on how to enable access logs in JBoss 7.

  • Go to JBoss/standalone/configuration folder
  • Add following in standalone.xml, look for domain:web syntax and ensure to add before closing </virtual-server> tag.
<access-log pattern="%a %t %H %p %U %s %S %T" rotate="true">
<directory path="." relative-to="jboss.server.log.dir"/>
</access-log>

Ex:

<subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host" native="false">
            <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
            <virtual-server name="default-host" enable-welcome-root="true">
                <alias name="localhost"/>
                <alias name="example.com"/>
                <access-log pattern="%a %t %H %p %U %s %S %T" rotate="true">
                            <directory path="." relative-to="jboss.server.log.dir"/>
                                    </access-log>
            </virtual-server>
        </subsystem>
  • Restart JBoss 7 server and verify the access logs under log folder.

You may refer following for valve patterns to capture in access log.

%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 resolveHostsis 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)

原文地址:http://chandank.com/application-server/tomcat/jboss-7-access-log-configuration

HOWTO: Configure Access Logging in Tomcat

ntroduction

Sometimes we need to log usage activity in tomcat.  It could be that tomcat is the main web server for the site and we want to record site activity, (hits, page views, errors).  It could be that tomcat is the application server and we want to see if there are any test systems hitting production or it could be a desire to correlate resource requests to exceptions.   This HowTo is meant to illustrate the steps necessary to set up access loging in tomcat.   At time of this writing, tomcat 6 is still the mainstream version in use, so this document will be using tomcat 6 for examples but I don‘t expect there to be too many differences that could not be applied to tomcat 5.5 or tomcat 7.

Enabling the Tomcat Access Logger

Tomcat access logging is enabled by modifying the server.xml file and uncommenting the Access Log Valve.   In a default tomcat implementation, the access log valve section is located within the Host element.   Uncommenting the entry will enable an access log that contains fields equivalent to a "common" log file format from Apache.   The defaults for the valve will result in a file named "localhost_access_log" followed by the date, followed by a ".txt" file extension.   IP addresses will be logged, not hostnames and log file will be written into the${tomcat.home}/logs directory.   The fields present in the log file using a common format are:

  • Client host name (recorded as an IP if the default resolveHosts is not changed to "true").
  • Remote logical username (which always prints a "-").
  • Remote authenticated user ID (if one exists)
  • Date and Time of the request
  • HTTP Method and URI requested
  • HTTP Response Status Code
  • Size, in bytes, of the response (excluding http response headers)

Below is a snippet of the relevants parts of a server.xml displaying the newly enabled access logging defaults:

01 <Host name="localhost"  appBase="webapps"
02             unpackWARs="true" autoDeploy="true"
03             xmlValidation="false" xmlNamespaceAware="false">
04  
05         <!-- SingleSignOn valve, share authentication between web applications
06              Documentation at: /docs/config/valve.html -->
07         <!--
08         <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
09         -->
10  
11         <!-- Access log processes all example.
12              Documentation at: /docs/config/valve.html -->
13          
14         <Valve className="org.apache.catalina.valves.AccessLogValve"directory="logs" 
15                prefix="localhost_access_log." suffix=".txt" pattern="common"resolveHosts="false"/>
16 </Host>

Customizing the Access Log

The common log format is ok but changing the pattern to combined adds the User-Agent (browser or robot type) and the referring web site and URI.   Tomcat also provides additional options to log things like the request protocol, the local port that received the request, user session ID‘s, incoming or outgoing request headers, etc.   A full list is documented at the Tomcat Configuration Reference Valve Component page.

If you are running a version of tomcat greater than version 6.0.21 or tomcat 7, you can take advantage of the new Remote IP Valve. For access logging, the nice thing about this valve is that it will swap the client IP with an IP address passed with the X-Forwarded-For header—automatically—if an IP address is passed in the X-Forwarded-For header.  Loading it is pretty easy. Just add the org.apache.catalina.valves.RemoteIpValve to your server.xml before your AccessLogValve declaration. For example:

01   <Host name="localhost"  appBase="webapps"
02     unpackWARs="true" autoDeploy="true"
03     xmlValidation="false" xmlNamespaceAware="false">
04  
05   <!-- SingleSignOn valve, share authentication between web applications
06     Documentation at: /docs/config/valve.html -->
07   <!--
08     <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
09   -->
10  
11   <!-- Remote IP Valve -->
12     <Valve className="org.apache.catalina.valves.RemoteIpValve" />
13  
14   <!-- Access log processes all example.
15     Documentation at: /docs/config/valve.html -->
16          
17   <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" 
18     prefix="localhost_access_log." suffix=".txt"
19     pattern="combined" resolveHosts="false"/>
20   -->
21  
22 </Host>

This is enough to get you started with the RemoteIP Valve but you‘re going to want to add some additional settings to customize it so that it is specific to your environment.   For example, if there are some F5 BigIP‘s load-balancing your servers, you will want to add the IP address(es) of the SNAT IP to RemoteIP Valve‘sinternalProxies property.

If you are using a version of tomcat 6 older than 6.0.21 and you want to store the X-Forwarded-For IP address instead, then you could modify the pattern property of your AccessLogValve. You‘ll need to remove the "common" or "combined" pattern and replace it with one of the following patterns:

1 Common Log Format: %{X-Forwarded-For}i %l %u %t "%r" %s %b
2 Combined Log Format: %{X-Forwarded-For}i %l %u %t %r %s %b %{User-Agent}i %{Referer}i

The main problem here, that RemoteIP Valve does take care of, is that you‘ll only get the X-Forwarded-For address in the logs. If you hit the app server directly, bypassing the device that is inserting the X-Forwarded-For header in the request, you won‘t get an IP address logged.  You will still log a request—you just will not know where it came from.

原文地址:http://www.techstacks.com/howto/configure-access-logging-in-tomcat.html

时间: 2024-10-09 23:01:25

Enable Access Logs in JBoss 7 and tomcat--转的相关文章

转 : JBoss Web和 Tomcat的区别

JBoss Web和 Tomcat的区别 在Web2.0的浪潮中,各种页面技术和框架不断涌现,为服务器端的基础架构提出了更高的稳定性和可扩展性的要求.近年来,作为开源中间件的全 球领导者,JBoss在J2EE应用服务器领域已成为发展最为迅速的应用服务器.在市场占有率和服务满意度上取得了巨大的成功,丝毫不逊色于其它的非开源 竞争对手,如WebSphere.WebLogic.Application Server.JBoss Web的诸多优越性能,正是其广为流行的原因. 基于Tomcat内核,青胜于蓝

【转】JBoss Web和 Tomcat的区别

转载于:http://www.verydemo.com/demo_c202_i780.html JBoss Web和 Tomcat的区别 在Web2.0的浪潮中,各种页面技术和框架不断涌现,为服务器端的基础架构提出了更高的稳定性和可扩展性的要求.近年来,作为开源中间件的全 球领导者,JBoss在J2EE应用服务器领域已成为发展最为迅速的应用服务器.在市场占有率和服务满意度上取得了巨大的成功,丝毫不逊色于其它的非开源 竞争对手,如WebSphere.WebLogic.Application Ser

JBoss Web和 Tomcat的区别

JBoss Web和 Tomcat的区别2009-12-14 11:18在Web2.0的浪潮中,各种页面技术和框架不断涌现,为服务器端的基础架构提出了更高的稳定性和可扩展性的要求.近年来,作为开源中间件的全 球领导者,JBoss在J2EE应用服务器领域已成为发展最为迅速的应用服务器.在市场占有率和服务满意度上取得了巨大的成功,丝毫不逊色于其它的非开源 竞争对手,如WebSphere.WebLogic.Application Server.JBoss Web的诸多优越性能,正是其广为流行的原因.

Access Logging

73.6 Configure Access Logging Access logs can be configured for Tomcat and Undertow via their respective namespaces. For instance, the following logs access on Tomcat with a custom pattern. server.tomcat.basedir=my-tomcat server.tomcat.accesslog.enab

JBoss和tomcat的区别

JBoss和tomcat的区别 注意JBoss和tomcat是不一样,JBoss是一个可伸缩的服务器平台,当你的EJB程序编制完成后,如果访问量增加,只要通过增加服务器硬件就可以实现多台服务器同时运算,提高了负载容量,这个性能容量理论上是没有限制的,理论上无最大支持在线人数的上限,对于JBoss/EJB这样的平台来说,无最大访问量限制一说. 这是JBoss/EJB不同于Spring /Tomcat等平台的最大优点所在,而且EJB 3.0也将出现轻量化解决方案,其实随着发展,已经模糊了轻量/重量的

Tomcat,JBoss与JBoss Web

最近接触到应用服务器JBoss,此外JBoss Web与Tomcat也同为web服务器,便查阅资料对三者进行比较,供大家参考. 一.Tomcat Tomcat 服务器是免费开源的Web 应用服务器.支持最新的Servlet 和JSP 规范.因为Tomcat 技术先进.性能稳定,而且免费,因而深受Java 爱好者的喜爱并得到了部分软件开发商的认可,成为目前比较流行的Web 应用服务器.          Tomcat和IIS.Apache等Web服务器一样,具有处理HTML页面的功能,不过,Tom

Tomcat、Weblogic、Jboss、WebSphere之间的区别和联系

Tomcat.Weblogic.Jboss.WebSphere之间的区别和联系 Websphere: 这是ibm公司的网上的信息.更详细的信息可以访问网站: http://www-306.ibm.com/software/cn/websphere/ WebSphere 产品家族和解决方案 业务整合整合服务器提供了一套用于应用程序整合和业务流程自动化的中央基础设施. 应用服务器应用服务器提供了运行互操作应用程序的平台. IBM Support for Apache Geronimo IBM Sup

http://wiki.apache.org/tomcat/HowTo

http://wiki.apache.org/tomcat/HowTo Contents Meta How do I add a question to this page? How do I contribute to Tomcat's documentation? Installation How do I set up and run Tomcat on Macintosh OS X? How do I set up and run Tomcat on Solaris 10? How do

tomcat 安装配置部署到nginx+tomcat+https

目录 1 Tomcat简介 2.下载并安装Tomcat服务 2.2 部署java环境 2.3 安装Tomcat 2.4 Tomcat目录介绍 (关注点 bin conf logs webapps) 2.5 启动Tomcat 3.2 Tomcat管理 8 搭建jpress--java 版本的wordpress tomcat 配置文件 conf/server.xml tomcat 自定义网站目录 Tomcat多实例 (多个虚拟主机) tomcat反向代理集群 tomcat监控 zabbix监控 ng