JBoss 7 is slightly different than earlier version JBoss 5 or 6. The procedure to enable access logs in JBoss 7 are also changed and you must being familiar on how to enable access logs in JB OSS 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.di R "/></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= "Jbos S.server.log.dir "/> </access-log> </virtual-server> </subsystem>
- Restart JBoss 7 Server and verify the Access logs under Log folder.
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 H TTP headers%h-remote host name (or IP address if resolvehostsis false)%h-request Protocol%l-remote logical username fro M Identd (always returns '-')%m-request method (GET, POST, etc.) %p-local port on which this request is 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 F Ormat%u-remote user that is 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 Compa Re later with Stacktraces)
Original address: 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 this tomcat is the main Web server for the site and we want to record site activity, (hits, page views, errors ). It could be this tomcat is the application server and we want to see if there was any test systems hitting production or I T could is a desire to correlate resource requests to exceptions. This HowTo was meant to illustrate the steps necessary to set up access loging in Tomcat. At time of this writing, Tomcat 6 was still the mainstream version in use, so this document would be using Tomcat 6 for exam Ples but I don't expect there to being too many differences that could not being 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. a de Fault Tomcat implementation, the Access log Valve section is located within the Host
element. Uncommenting The entry would enable an access log of contains fields equivalent to a "common" log file format from Apache. The defaults for the valve would result in a file named "Localhost_access_log" followed by the date, followed by a " . txt "file extension. IP addresses would be logged, not hostnames and log file would be written into the ${tomcat.home}/logs
&nb Sp;directory. The present in the log file using a common format is:
- Client host name (recorded as an IP if the default was not
resolveHosts
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" > |
05 |
<!-- SingleSignOn valve, share authentication between web applications |
06 |
Documentation at: /docs/config/valve.html --> |
08 |
<Valve className="org.apache.catalina.authenticator.SingleSignOn" /> |
11 |
<!-- Access log processes all example. |
12 |
Documentation at: /docs/config/valve.html --> |
14 |
< Valve className = "org.apache.catalina.valves.AccessLogValve" directory = "logs" |
15 |
prefix = "localhost_access_log." suffix = ".txt" pattern = "common" resolveHosts = "false" /> |
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 R Equest, user session ID ' s, incoming or outgoing request headers, etc. A full list was documented at The tomcat Configuration Reference Valve component page.
If You is running a version of Tomcat greater than version 6.0.21 or Tomcat 7, you can take advantage of the new Remot e IP valve. for Access logging, the nice thing about this Valve are that it'll swap the client IP with an IP address Passed with the X-forwarded-for header-automatically-if a 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" > |
05 |
<!-- SingleSignOn valve, share authentication between web applications |
06 |
Documentation at: /docs/config/valve.html --> |
08 |
<Valve className="org.apache.catalina.authenticator.SingleSignOn" /> |
11 |
<!-- Remote IP Valve --> |
12 |
< Valve className = "org.apache.catalina.valves.RemoteIpValve" /> |
14 |
<!-- Access log processes all example. |
15 |
Documentation at: /docs/config/valve.html --> |
17 |
< Valve className = "org.apache.catalina.valves.AccessLogValve" directory = "logs" |
18 |
prefix = "localhost_access_log." suffix = ".txt" |
19 |
pattern = "combined" resolveHosts = "false" /> |
This was enough to get started with the Remoteip Valve but you ' re going to want to add some additional settings to Cust Omize it was specific to your environment. For example, if there is some F5 BigIP ' s load-balancing your servers, you'll want to add the IP address (es) of the SNAT IP to Remoteip Valve's property internalProxies
.
If you is using a version of Tomcat 6 older than 6.0.21 and you want to store the x-forwarded-for IP address instead, the n You could modify the property of pattern
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's Remoteip Valve does take care of, was that's you'll only get the x-forwarded-for address in the L OGs. If you hit the app server directly, bypassing the device which is inserting the x-forwarded-for header in the request, you Won ' t get an IP address logged. You'll still log a request-you just won't know where it came from.
Original address: http://www.techstacks.com/howto/configure-access-logging-in-tomcat.html
Enable Access Logs in JBoss 7 and tomcat--go