ServersApache Guide: Logging, Part 3 -- Custom Logs Page 2

Apache Guide: Logging, Part 3 — Custom Logs Page 2




So, the LogFormat line above, from the default httpd.conf file, creates a
log format called common, which contains the remote host, remote logname,
remote user, the time of the transaction, the first line of the request, the
status of the request, and the number of bytes sent. Which is pretty much
what I went through in my last article.

Now, sometimes you’ll only want a particlar piece of information logged if it is
defined. These is what the “…”, referred to above, provides for. If, between
the % and the variable, you put one or more HTTP status codes, the variable will
only be logged in the event that the request returns one of those status codes.
So, if you’re trying to keep a log of all the broken links on your
site, you might have the following:

     LogFormat %404{Referer}i BrokenLinks

Conversely, if you want to log requests that don't match a particular code,
put a ! in there:

     LogFormat %!200U SomethingWrong

CustomLog

Once you have set up one or more LogFormats, you just have to apply them
to a particular log file. This is done with the CustomLog directive.
You can set up as many log files as you like (well, not really, but you
can set up a lot of them). Each one needs to specify a lof file location,
and which LogFormat you want to use:

     CustomLog /var/log/httpd/bogus_log SomethingWrong
     CustomLog /usr/local/apache/logs/broken BrokenLinks
     CustomLog /usr/local/apache/logs/access_log common

Conclusion

That's really all there is to it. You can put just about any information in
a log file, and format it just about any way you like.

The only disadvantage to doing this is that if you get some off the shelf log
analysis application, it will assume that you are using common or combined
log format, since those are the ones that are most widely in use.

That's all 'til next time. In the next article, I'll talk about parsing your
log files -- running some sort of analysis tool on them to get useful information
out. That is the thing that your boss really wants. How many people looked at
the web site yesterday? Where did they find out about us? Are they coming
back, or just one-time visitors? And so on.

Send me a note at [email protected] if you have any questions, or suggestions for another article.
Or make a comment in the Talkback area.

Want to discuss logfiles with other Apache Today readers? Then check out the discussions at Apache Today Discussions.

Latest Posts

Related Stories