Your Daily Source for Apache News and Information |
Breaking News | Preferences | Contribute | Triggers | Link Us | Search | About |
|
By Long ago, log files came in one format. It was called the common format, and you were pretty much stuck with it. Then came custom log file format, and it turned out to be such a good idea that even the common format was reimplemented as a custom log file format. In this article, you'll find out how to make your log files look like whatever you want, and have whatever information in them that you want. OverviewHere's the lightning overview for those of you that just want to get something working, and don't care about all the details. You'll need to look at the
LogFormatThe For example, in your default LogFormat "%h %l %u %t \"%r\" %>s %b" common This directive creates a log format called "common", which is in the format specified in quotes. Each one of those letters means a particular piece of information, which is put into the log file in the order indicated. The available variables, and their meanings, are listed in the documentation, and are reproduced below: %...a: Remote IP-address %...A: Local IP-address %...B: Bytes sent, excluding HTTP headers. %...b: Bytes sent, excluding HTTP headers. In CLF format i.e. a '-' rather than a 0 when no bytes are sent. %...{FOOBAR}e: The contents of the environment variable FOOBAR %...f: Filename %...h: Remote host %...H The request protocol %...{Foobar}i: The contents of Foobar: header line(s) in the request sent to the server. %...l: Remote logname (from identd, if supplied) %...m The request method %...{Foobar}n: The contents of note "Foobar" from another module. %...{Foobar}o: The contents of Foobar: header line(s) in the reply. %...p: The canonical Port of the server serving the request %...P: The process ID of the child that serviced the request. %...q The query string (prepended with a ? if a query string exists, otherwise an empty string) %...r: First line of request %...s: Status. For requests that got internally redirected, this is the status of the *original* request --- %...>s for the last. %...t: Time, in common log format time format (standard english format) %...{format}t: The time, in the form given by format, which should be in strftime(3) format. (potentially localised) %...T: The time taken to serve the request, in seconds. %...u: Remote user (from auth; may be bogus if return status (%s) is 401) %...U: The URL path requested. %...v: The canonical ServerName of the server serving the request. %...V: The server name according to the UseCanonicalName setting. In each case, the "..." indicates an (optional) condition. If the condition is met, then the particular. If the condition is ommitted, then the variable will be replaced with a "-" if it is not defined. I'll give some examples of this in a minute. So, the 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 CustomLogOnce you have set up one or more CustomLog /var/log/httpd/bogus_log SomethingWrong CustomLog /usr/local/apache/logs/broken BrokenLinks CustomLog /usr/local/apache/logs/access_log common ConclusionThat'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 Next TimeThat'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 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. |
|
Talkback(s) | Name | Date | ||
|
Sep 6, 2000, 15:17:58 | |||
|
Sep 11, 2000, 18:03:53 | |||
|
Sep 6, 2000, 23:13:16 | |||
|
Sep 9, 2000, 22:00:46 | |||
|
Sep 15, 2000, 10:51:28 | |||
|
Sep 24, 2000, 14:14:19 | |||
|
Dec 11, 2000, 18:35:30 | |||
|
Jul 4, 2001, 08:22:51 |
About Triggers | Newsletters | Media Kit | Security | Triggers | Login |
All times are recorded in UTC. Linux is a trademark of Linus Torvalds. Powered by Linux 2.2.12, Apache 1.3.9. and PHP 3.14 Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy. |