Log response headers in apache

18 November 2010 13:44

I’ve been working on tweaking some apache logging on a few servers and one of the things I needed to log was a response header. The response header in question is an identifier with information about where the request was served from.

A quick look through the apache log docs doesn’t give any clue on how to do this. I details request header logging but not response. A google search also didn’t really come up with anything that useful until I stumbled on an article over on the  apache week site.

A quick modification of the httpd.conf to duplicate the “common” log entry left me with this:

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{HEADER_NAME}o\"" common2

The key element is the “o”, if you have %{HEADER_NAME}i you’ll get the request header, if you have %{HEADER_NAME}o you’ll get the response header.

This results in the following entry in the log file:

127.0.0.1 - - [18/Nov/2010:13:37:39 +0000] "GET / HTTP/1.1" 200 31006 "HEADER_VALUE"

Filed: Technology // Tagged: , , ,

You can follow any responses to this entry through the RSS 2.0 feed.

You can leave a comment or leave a trackback from your own site.

  • Simon

    Thanks, this helped a lot. Maybe you can add the line
    CustomLog /var/log/apache2/response.log common2 (or similiar). It took me some time to recognize I had to add the CustomLog line to tell apache to really log the response stuff ;-)

    Do you know of a way to log the whole response body?

  • http://ianwinter.co.uk Ian

    This is the full list, it’s not obvious if you can return it all. I imagine you can with a wildcard perhaps.

 
What's ianteresting?   •   Twitter   •   About   •   Contact
©2014 Ian Winter. All Rights Reserved.   •   Powered by WordPress   •   Hosted at Memset