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

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

  1. 转 : JBoss Web和 Tomcat的区别

    JBoss Web和 Tomcat的区别 在Web2.0的浪潮中,各种页面技术和框架不断涌现,为服务器端的基础架构提出了更高的稳定性和可扩展性的要求.近年来,作为开源中间件的全 球领导者,JBoss在 ...

  2. 【转】JBoss Web和 Tomcat的区别

    转载于:http://www.verydemo.com/demo_c202_i780.html JBoss Web和 Tomcat的区别 在Web2.0的浪潮中,各种页面技术和框架不断涌现,为服务器端 ...

  3. JBoss Web和Tomcat的区别

    在Web2.0的时代,基于Tomcat内核的JBoss在J2EE应用服务器领域已成为发展最为迅速的应用服务器.这一青出于蓝而胜于蓝的产品与Tomcat的区别又在哪里? 基于Tomcat内核,青胜于蓝. ...

  4. Access Logging Tomcat

    73.6 Configure Access Logging server.tomcat.accesslog.buffered=true # Buffer output such that it is ...

  5. Embedded servlet containers

    73. Embedded servlet containers 73.1 Add a Servlet, Filter or Listener to an application There are t ...

  6. Tomcat access log配置

    在tomcat的access中打印出请求的情况可以帮助我们分析问题,通常比较关注的有访问IP.线程号.访问url.返回状态码.访问时间.持续时间. 在Spring boot中使用了内嵌的tomcat, ...

  7. springboot中配置tomcat的access log

    在tomcat的access中打印出请求的情况可以帮助我们分析问题,通常比较关注的有访问IP.线程号.访问url.返回状态码.访问时间.持续时间. 在Spring boot中使用了内嵌的tomcat, ...

  8. 【Tomcat】tomcat logs 目录下各日志文件的含义

      tomcat每次启动时,自动在logs目录下生产以下日志文件,按照日期自动备份.可以帮助我们更好的找出错误.   一. 认识各种目录的作用及记录的信息 目录

  9. 【转】tomcat logs 目录下各日志文件的含义

    tomcat每次启动时,自动在logs目录下生产以下日志文件,按照日期自动备份   localhost.2016-07-05.txt   //经常用到的文件之一 ,程序异常没有被捕获的时候抛出的地方 ...

随机推荐

  1. linux安装python使用的MySQLdb

    安装mysqldb模块需已安装mysql 使用pip安装MySQLdb pip install mysql-python mac os安装mysqldb sudo pip install mysql- ...

  2. PHP 之 Laravel 框架安装及相关开源软件

    Laravel 被称为简洁.优雅的PHP开发框架,但第一次接触此框架的人有不少都卡在了安装上,其实在 Linux 下只需要很简单的几步就可以搞定,这里我们以 CentOS 下 PHP + Nginx ...

  3. h.264 去块滤波

    块效应及其产生原因 我们在观看视频的时候,在运动剧烈的场景常能观察到图像出现小方块,小方块在边界处呈现不连续的效果(如下图),这种现象被称为块效应(blocking artifact). 首先我们需要 ...

  4. mongodb 查看数据库和表大小

    1.查看数据库 > db.stats(); { "db" : "test", //当前数据库 "collections" : 3, / ...

  5. SpringMVC+Json构建基于Restful风格的应用(转)

    一.spring 版本:spring-framework-3.2.7.RELEASE 二.所需其它Jar包: 三.主要代码: web.xml <?xml version="1.0&qu ...

  6. arp命令(windows ),nmap查看局域网内所有主机IP和MAC

    ARP命令详解 ARP是一个重要的TCP/IP协议,并且用于确定对应IP地址的网卡物理地址.实用arp命令,我们能够查看本地计算机或另一台计算机的ARP高速缓存中的当前内容.此外,使用arp命令,也可 ...

  7. NOIP2014酱油记

    尘埃落定,来补一下酱油记吧... day-1 晚上老师说有xyz的noip模拟赛,于是果断请假来做(shou)题(nve),题目真是理(S)性(X)愉(B)悦(K),然后就爆零了!感觉noip要爆零滚 ...

  8. android滑动删除的多种实现方式(一)

    个人习惯,先上图 同事是个妹子(这点很重要),写滑动删除动能的时候用到了SwipeLayout,然后悲催的是,滑动时间被拦截了,解决方法先不提,在(一)中先讲解SwipeLayout下载listvie ...

  9. 数据结构(莫队算法):HH的项链

    问题描述: HH有一串由各种漂亮的贝壳组成的项链.HH相信不同的贝壳会带来好运,所以每次散步 完后,他都会随意取出一段贝壳,思考它们所表达的含义.HH不断地收集新的贝壳,因此, 他的项链变得越来越长. ...

  10. 在Xcode中使用Clang Format

    Xcode中的Re-Indent,顾名思义,只是一个调整缩进的功能,完全依赖它来进行代码格式化显然不够用.我们使用了一个叫做ClangFormat-Xcode的插件,配合Re-Indent一起来做代码 ...