SHARE
Facebook X Pinterest WhatsApp

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

Written By
thumbnail Rich Bowen
Rich Bowen
Jul 20, 2010
ServerWatch content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More



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 ApacheToday@rcbowen.com 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.

thumbnail Rich Bowen

Rich Bowen is a ServerWatch contributor.

Recommended for you...

What Is a Container? Understanding Containerization
What Is a Print Server? | How It Works and What It Does
Nisar Ahmad
Dec 8, 2023
What Is a Network Policy Server (NPS)? | Essential Guide
Virtual Servers vs. Physical Servers: Comparison and Use Cases
Ray Fernandez
Nov 14, 2023
ServerWatch Logo

ServerWatch is a top resource on servers. Explore the latest news, reviews and guides for server administrators now.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.