{"id":410,"date":"2007-12-31T13:58:19","date_gmt":"2007-12-31T18:58:19","guid":{"rendered":"http:\/\/blogs.n1zyy.com\/n1zyy\/2007\/12\/31\/custom-logformat-with-apache\/"},"modified":"2007-12-31T13:58:19","modified_gmt":"2007-12-31T18:58:19","slug":"custom-logformat-with-apache","status":"publish","type":"post","link":"https:\/\/blogs.n1zyy.com\/n1zyy\/2007\/12\/31\/custom-logformat-with-apache\/","title":{"rendered":"Custom LogFormat with Apache"},"content":{"rendered":"<p>Posting this in the hopes that it&#8217;ll help someone at some point&#8230;.<\/p>\n<p>Using Apache (Apache2 in my case, but I&#8217;m not sure it matters), you can customize the format for log files like access_log. Apache has a good <a href=\"http:\/\/httpd.apache.org\/docs\/2.0\/mod\/mod_log_config.html\">page describing the variables you can use<\/a>. But it doesn&#8217;t tell you everything you need to know!<\/p>\n<p>The first question is where you put it&#8230; You can just specify it in httpd.conf (I put it near the end, but I don&#8217;t think its placement matters terribly, as long as it&#8217;s not in the middle of a section. It doesn&#8217;t go in any directives or anything. You can also insert it inside a VirtualHost directive if you only want it to apply to those. (Don&#8217;t put it inside a Directory directive!)<\/p>\n<p>The second thing is something that&#8217;s not really specified anywhere: <b>specifying a LogFormat without then specifying a CustomLog directive accomplishes nothing<\/b>! I wanted to keep Apache logging in the default directory (\/var\/log\/apache2\/access_log on Gentoo), so I just set the LogFormat to something I wanted. And nothing happened.<\/p>\n<p>You specify the format in CustomLog as well, so it&#8217;s handy to use LogFormat to assign a &#8220;nickname&#8221;:<\/p>\n<blockquote><pre>LogFormat \"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"\" n1zyy\nCustomLog \/var\/log\/apache2\/access_log n1zyy<\/pre><\/blockquote>\n<p>The first line sets the &#8220;n1zyy&#8221; &#8216;nickname&#8217; to refer to to the format I specify. The next line sets a &#8220;custom&#8221; log file (in this case, it&#8217;s the same as the default, but I digress. It won&#8217;t work if I don&#8217;t specify it.) Then I tell it to use the format named &#8220;n1zyy.&#8221;<\/p>\n<p>Once this is set up, you want to reload Apache, since it won&#8217;t notice your changes until you do.<\/p>","protected":false},"excerpt":{"rendered":"<p>Posting this in the hopes that it&#8217;ll help someone at some point&#8230;. Using Apache (Apache2 in my case, but I&#8217;m not sure it matters), you can customize the format for log files like access_log. Apache has a good page describing &hellip; <a href=\"https:\/\/blogs.n1zyy.com\/n1zyy\/2007\/12\/31\/custom-logformat-with-apache\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,13,22],"tags":[],"class_list":["post-410","post","type-post","status-publish","format-standard","hentry","category-computers","category-linux-tips","category-programming"],"_links":{"self":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts\/410","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/comments?post=410"}],"version-history":[{"count":0,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts\/410\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/media?parent=410"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/categories?post=410"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/tags?post=410"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}