Why and how to log Content-Type in apache access log

It is very handy to log Content-Type in apache access log. It can be used to grep visit of specific content-type (e.g. text/html). Here is apache configuration which can be used to enable Content-Type in access log:

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"ct:%{Content-Type}o\"" mycombined
CustomLog "|/usr/bin/rotatelogs /var/log/apache2/access_log.%Y-%m-%d 86400" mycombined

Here is how a log entry looks like with above configuration: - - [20/Nov/2015:17:39:16 +0000] "GET /img/search_icon-24.png HTTP/1.1" 200 1295 "http://infoheap.com/convert-text-to-speech-on-mac-using-utility-say/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/601.2.7 (KHTML, like Gecko) Version/9.0.1 Safari/601.2.7" "ct:image/png"
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments