Trying to get request parameter out to access log in tomcat
Asked Answered
K

2

5

I trying to investigate how often a particular HTTP request is getting send to a web site. The request is a POST and has a parameter named "_method". I can see this in firebug getting net over.

I need to check the value of this "_method" parameter, so following the documentation http://tomcat.apache.org/tomcat-6.0-doc/config/valve.html#Access_Log_Valve I add the following to the tomcat access configuration for the valve

%{_method}r

But it is not coming out in access logs.

I wonder is that because of the underscore?

Note, the parameter name cannot be changed.

Kletter answered 3/7, 2012 at 13:45 Comment(0)
K
7

OK, What I had to do was use the ExtendedAccessLogValve.

I added the below to my server.xml

    <Valve className="org.apache.catalina.valves.ExtendedAccessLogValve" directory="logs" pattern="c-dns x-H(remoteUser) date time cs-method cs-uri x-H(protocol) sc-status bytes x-P(_method)" prefix="localhost_extended_access_log." resolveHosts="false" suffix=".txt"/>

The part x-P(_method) is the crucial part which gave it to me.

I am including answer for any on-lookers.

Kletter answered 3/7, 2012 at 14:20 Comment(0)
N
3
%{xxx}r 

is used for an "attribute in the ServletRequest" not for HTTP parameters (which are what I assume you mean, if you can see it in Firebug). ServletRequest attributes will be entirely server-side, so you would not be able to see them in Firebug.

If you want to output HTTP parameters (and it's not a GET, ie. they are in the URL) I think you would have to use Request Dumper Valve documented on that same page.

Difference between getAttribute() and getParameter() explains the difference if the above is not clear.

Number answered 3/7, 2012 at 13:52 Comment(2)
Good point. Forgot about that. Think I need to use ExtendedAccessLogValve. Will test that and get it working and then post updated.Kletter
Here's an example for anyone else having trouble with this: <Valve className="org.apache.catalina.valves.AccessLogValve" conditionIf="LogMe" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b,customAttribute: %{customAttribute}r" />Bauer

© 2022 - 2024 — McMap. All rights reserved.