mod_log_config.c revision 1b21d7b3d97def358b2e923655edeb16613a1c31
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin/* ====================================================================
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * The Apache Software License, Version 1.1
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Copyright (c) 2000 The Apache Software Foundation. All rights
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * Redistribution and use in source and binary forms, with or without
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * modification, are permitted provided that the following conditions
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * 1. Redistributions of source code must retain the above copyright
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * notice, this list of conditions and the following disclaimer.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * 2. Redistributions in binary form must reproduce the above copyright
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * notice, this list of conditions and the following disclaimer in
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * the documentation and/or other materials provided with the
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * distribution.
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * 3. The end-user documentation included with the redistribution,
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * if any, must include the following acknowledgment:
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * "This product includes software developed by the
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Apache Software Foundation (http://www.apache.org/)."
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Alternately, this acknowledgment may appear in the software itself,
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * if and wherever such third-party acknowledgments normally appear.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * 4. The names "Apache" and "Apache Software Foundation" must
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * not be used to endorse or promote products derived from this
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * software without prior written permission. For written
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * permission, please contact apache@apache.org.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * 5. Products derived from this software may not be called "Apache",
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * nor may "Apache" appear in their name, without prior written
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * permission of the Apache Software Foundation.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * SUCH DAMAGE.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * ====================================================================
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * This software consists of voluntary contributions made by many
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * individuals on behalf of the Apache Software Foundation. For more
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * information on the Apache Software Foundation, please see
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Portions of this software are based upon public domain software
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * originally written at the National Center for Supercomputing Applications,
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * University of Illinois, Urbana-Champaign.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Modified by djm@va.pubnix.com:
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * If no TransferLog is given explicitly, decline to log.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * This is module implements the TransferLog directive (same as the
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * common log module), and additional directives, LogFormat and CustomLog.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * TransferLog fn Logs transfers to fn in standard log format, unless
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * a custom format is set with LogFormat
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * LogFormat format Set a log format from TransferLog files
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * CustomLog fn format
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Log to file fn with format given by the format
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * CookieLog fn For backwards compatability with old Cookie
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * logging module - now deprecated.
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * There can be any number of TransferLog and CustomLog
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * commands. Each request will be logged to _ALL_ the
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * named files, in the appropriate format.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * If no TransferLog or CustomLog directive appears in a VirtualHost,
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * the request will be logged to the log file(s) defined outside
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * the virtual host section. If a TransferLog or CustomLog directive
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * appears in the VirtualHost section, the log files defined outside
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * the VirtualHost will _not_ be used. This makes this module compatable
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * with the CLF and config log modules, where the use of TransferLog
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * inside the VirtualHost section overrides its use outside.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * <VirtualHost>
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * LogFormat "... custom format ..."
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * CustomLog log/virtual_useragents "%t %{user-agent}i"
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * </VirtualHost>
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * This will log using CLF to access_log any requests handled by the
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * main server, while any requests to the virtual host will be logged
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * with the "... custom format..." to virtual_only _AND_ using
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * the custom user-agent log to virtual_useragents.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Note that the NCSA referer and user-agent logs are easily added with
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * CustomLog logs/referer "%{referer}i -> %U"
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * CustomLog logs/agent "%{user-agent}i"
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * RefererIgnore functionality can be obtained with conditional
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * logging (SetEnvIf and CustomLog ... env=!VAR).
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * But using this method allows much easier modification of the
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * log format, e.g. to log hosts along with UA:
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * CustomLog logs/referer "%{referer}i %U %h"
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * The argument to LogFormat and CustomLog is a string, which can include
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * literal characters copied into the log files, and '%' directives as
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...B: bytes sent, excluding HTTP headers.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...b: bytes sent, excluding HTTP headers in CLF format, i.e. a '-'
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * when no bytes where sent (rather than a '0'.
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * %...c: Status of the connection.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * 'X' = connection aborted before the response completed.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * '+' = connection may be kept alive after the response is sent.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * '-' = connection will be closed after the response is sent.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...{FOOBAR}C: The contents of the HTTP cookie FOOBAR
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...{FOOBAR}e: The contents of the environment variable FOOBAR
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...f: filename
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...h: remote host
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...a: remote IP-address
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...A: local IP-address
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...{Foobar}i: The contents of Foobar: header line(s) in the request
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * sent to the client.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...l: remote logname (from identd, if supplied)
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...{Foobar}n: The contents of note "Foobar" from another module.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...{Foobar}o: The contents of Foobar: header line(s) in the reply.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...p: the port the request was served to
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...P: the process ID of the child that serviced the request.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...r: first line of request
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...s: status. For requests that got internally redirected, this
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * is status of the *original* request --- %...>s for the last.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...t: time, in common log format time format
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...{format}t: The time, in the form given by format, which should
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * be in strftime(3) format.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...T: the time taken to serve the request, in seconds.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...D: the time taken to serve the request, in micro seconds.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...u: remote user (from auth; may be bogus if return status (%s) is 401)
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...U: the URL path requested.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...v: the configured name of the server (i.e. which virtual host?)
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...V: the server name according to the UseCanonicalName setting
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...m: the request method
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...H: the request protocol
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...q: the query string prepended by "?", or empty if no query string
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * The '...' can be nothing at all (e.g. "%h %u %r %s %b"), or it can
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * indicate conditions for inclusion of the item (which will cause it
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * to be replaced with '-' if the condition is not met). Note that
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * there is no escaping performed on the strings from %r, %...i and
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * %...o; some with long memories may remember that I thought this was
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * a bad idea, once upon a time, and I'm still not comfortable with
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * it, but it is difficult to see how to "do the right thing" with all
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * of '%..i', unless we URL-escape everything and break with CLF.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * The forms of condition are a list of HTTP status codes, which may
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * or may not be preceded by '!'. Thus, '%400,501{User-agent}i' logs
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * User-agent: on 400 errors and 501 errors (Bad Request, Not
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Implemented) only; '%!200,304,302{Referer}i' logs Referer: on all
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * requests which did *not* return some sort of normal status.
#include "apr_strings.h"
#include "apr_lib.h"
#define APR_WANT_STRFUNC
#include "apr_want.h"
#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_log.h"
#include "http_protocol.h"
#include <unistd.h>
#ifdef HAVE_LIMITS_H
#include <limits.h>
#ifdef PIPE_BUF
const char *default_format_string;
const char *fname;
const char *format_string;
char *condition_var;
#ifdef BUFFERED_LOGS
char *arg;
int condition_sense;
int want_orig;
return format_integer(p, i);
return stuff;
return ap_get_remote_logname(r);
return rvalue;
: r->the_request;
return r->filename;
return r->uri;
return r->method;
return r->protocol;
if (!r->sent_bodyct) {
if (!r->sent_bodyct) {
if (cp) {
return cp;
const char *cookies;
const char *start_cookie;
if (end_cookie) {
return cookie;
return NULL;
char sign;
int timz;
if (timz < 0) {
/ APR_USEC_PER_SEC);
return ap_get_server_name(r);
static struct log_item_list {
char ch;
int want_orig_default;
} log_item_keys[] = {
return &log_item_keys[i];
return NULL;
const char **sa)
s = *sa;
s = *sa;
*sa = s;
return NULL;
const char *s = *sa;
struct log_item_list *l;
while (apr_isdigit(*++s)) {
l = find_log_func(*s++);
*sa = s;
return NULL;
char *res;
return NULL;
s = APR_EOL_STR;
const char *cp;
int in_list = 0;
#ifdef BUFFERED_LOGS
char *str, *s;
const char **strs;
int *strl;
char *envar;
return DECLINED;
return DECLINED;
return DECLINED;
orig = r;
while (r->next) {
r = r->next;
#ifdef BUFFERED_LOGS
apr_size_t w;
s += strl[i];
w = len;
s += strl[i];
s += strl[i];
return OK;
return OK;
return mls;
return add;
const char *name)
return err_string;
return err_string;
const char *fn)
{NULL}
!= APR_SUCCESS) {
#ifdef BUFFERED_LOGS
return cls;
const char *dummy;
const char *format;
if (format) {
if (format) {
if (format) {
return NULL;
#ifdef BUFFERED_LOGS
for (; s; s = s->next) {
if (log_list) {
return APR_SUCCESS;
open_multi_logs(s, p);
open_multi_logs(s, p);
#ifdef BUFFERED_LOGS