views:

2743

answers:

3

Imagine you have a site API that accepts data in the form of GET requests with parameters, or as POST requests (say, with standard url-encoded, &-separated POST data). If you want to log and analyze API calls, the GET requests will be easy, because they will be in the apache log. Is there a simple way to get the POST data in the apache log as well?

(Of course we could log the POST data explicitly in the application, but I'd like to have an configuration-level way that let me not worry about it in code.)

+1  A: 

I would do it in the application, actually. It's still configurable at runtime, depending on your logger system, of course. For example, if you use Apache Log (log4j/cxx) you could configure a dedicated logger for such URLs and then configure it at runtime from an XML file.

Assaf Lavie
My concern there is that EVERY api handler will have to log the data at the beginning -- easy to forget as you're adding, and at best it's just added boilerplate.
Kevin Weil
+1  A: 

Not exactly an answer, but I have never heard of a way to do this in Apache itself. I guess it might be possible with an extension module, but I don't know whether one has been written.

One concern is that POST data can be pretty large, and if you don't put some kind of limit on how much is being logged, you might run out of disk space after a while. It's a possible route for hackers to mess with your server.

David Zaslavsky
I agree with the later half completely! As there is no limit on the POST data it could include all sorts of data, including passwords, which you wouldn't want to store in a log. There maybe other secure and large data you don't want in the log.
Darryl Hein
A: 

Use Apache's mod_dumpio. Be careful for obvious reasons.

Spider