mod_log_config.c revision e95f5a6ebefb83d0e8a82cbc4db7d354957a817d
36488004520b3a22fbd37ef8e10e5641be154ac1slive/* ====================================================================
36488004520b3a22fbd37ef8e10e5641be154ac1slive * The Apache Software License, Version 1.1
5f5d1b4cc970b7f06ff8ef6526128e9a27303d88nd * Copyright (c) 2000 The Apache Software Foundation. All rights
36488004520b3a22fbd37ef8e10e5641be154ac1slive * reserved.
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding * Redistribution and use in source and binary forms, with or without
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding * modification, are permitted provided that the following conditions
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding * 1. Redistributions of source code must retain the above copyright
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding * notice, this list of conditions and the following disclaimer.
acc36ab93565d2880447d535da6ca6e5feac7a70nd * 2. Redistributions in binary form must reproduce the above copyright
acc36ab93565d2880447d535da6ca6e5feac7a70nd * notice, this list of conditions and the following disclaimer in
acc36ab93565d2880447d535da6ca6e5feac7a70nd * the documentation and/or other materials provided with the
acc36ab93565d2880447d535da6ca6e5feac7a70nd * distribution.
acc36ab93565d2880447d535da6ca6e5feac7a70nd * 3. The end-user documentation included with the redistribution,
acc36ab93565d2880447d535da6ca6e5feac7a70nd * if any, must include the following acknowledgment:
acc36ab93565d2880447d535da6ca6e5feac7a70nd * "This product includes software developed by the
acc36ab93565d2880447d535da6ca6e5feac7a70nd * Apache Software Foundation (http://www.apache.org/)."
7db9f691a00ead175b03335457ca296a33ddf31bnd * Alternately, this acknowledgment may appear in the software itself,
36488004520b3a22fbd37ef8e10e5641be154ac1slive * if and wherever such third-party acknowledgments normally appear.
36488004520b3a22fbd37ef8e10e5641be154ac1slive * 4. The names "Apache" and "Apache Software Foundation" must
36488004520b3a22fbd37ef8e10e5641be154ac1slive * not be used to endorse or promote products derived from this
36488004520b3a22fbd37ef8e10e5641be154ac1slive * software without prior written permission. For written
36488004520b3a22fbd37ef8e10e5641be154ac1slive * permission, please contact apache@apache.org.
36488004520b3a22fbd37ef8e10e5641be154ac1slive * 5. Products derived from this software may not be called "Apache",
36488004520b3a22fbd37ef8e10e5641be154ac1slive * nor may "Apache" appear in their name, without prior written
36488004520b3a22fbd37ef8e10e5641be154ac1slive * permission of the Apache Software Foundation.
36488004520b3a22fbd37ef8e10e5641be154ac1slive * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36488004520b3a22fbd37ef8e10e5641be154ac1slive * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
36488004520b3a22fbd37ef8e10e5641be154ac1slive * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
7d15331eeb5429d7148d13d6fd914a641bf1c000pquerna * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
36488004520b3a22fbd37ef8e10e5641be154ac1slive * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36488004520b3a22fbd37ef8e10e5641be154ac1slive * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36488004520b3a22fbd37ef8e10e5641be154ac1slive * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
36488004520b3a22fbd37ef8e10e5641be154ac1slive * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
36488004520b3a22fbd37ef8e10e5641be154ac1slive * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36488004520b3a22fbd37ef8e10e5641be154ac1slive * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
36488004520b3a22fbd37ef8e10e5641be154ac1slive * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36488004520b3a22fbd37ef8e10e5641be154ac1slive * SUCH DAMAGE.
36488004520b3a22fbd37ef8e10e5641be154ac1slive * ====================================================================
36488004520b3a22fbd37ef8e10e5641be154ac1slive * This software consists of voluntary contributions made by many
36488004520b3a22fbd37ef8e10e5641be154ac1slive * individuals on behalf of the Apache Software Foundation. For more
96aee4c18ac74113f91235b99233431769cd1e31jsl * information on the Apache Software Foundation, please see
36488004520b3a22fbd37ef8e10e5641be154ac1slive * Portions of this software are based upon public domain software
36488004520b3a22fbd37ef8e10e5641be154ac1slive * originally written at the National Center for Supercomputing Applications,
36488004520b3a22fbd37ef8e10e5641be154ac1slive * University of Illinois, Urbana-Champaign.
ce43c81d272d53dfb676aa28cb376014f4dcace3rbowen * Modified by djm@va.pubnix.com:
ce43c81d272d53dfb676aa28cb376014f4dcace3rbowen * If no TransferLog is given explicitly, decline to log.
36488004520b3a22fbd37ef8e10e5641be154ac1slive * This is module implements the TransferLog directive (same as the
36488004520b3a22fbd37ef8e10e5641be154ac1slive * common log module), and additional directives, LogFormat and CustomLog.
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim * TransferLog fn Logs transfers to fn in standard log format, unless
36488004520b3a22fbd37ef8e10e5641be154ac1slive * a custom format is set with LogFormat
36488004520b3a22fbd37ef8e10e5641be154ac1slive * LogFormat format Set a log format from TransferLog files
36488004520b3a22fbd37ef8e10e5641be154ac1slive * CustomLog fn format
36488004520b3a22fbd37ef8e10e5641be154ac1slive * Log to file fn with format given by the format
36488004520b3a22fbd37ef8e10e5641be154ac1slive * CookieLog fn For backwards compatability with old Cookie
36488004520b3a22fbd37ef8e10e5641be154ac1slive * logging module - now deprecated.
36488004520b3a22fbd37ef8e10e5641be154ac1slive * There can be any number of TransferLog and CustomLog
36488004520b3a22fbd37ef8e10e5641be154ac1slive * commands. Each request will be logged to _ALL_ the
36488004520b3a22fbd37ef8e10e5641be154ac1slive * named files, in the appropriate format.
36488004520b3a22fbd37ef8e10e5641be154ac1slive * If no TransferLog or CustomLog directive appears in a VirtualHost,
36488004520b3a22fbd37ef8e10e5641be154ac1slive * the request will be logged to the log file(s) defined outside
36488004520b3a22fbd37ef8e10e5641be154ac1slive * the virtual host section. If a TransferLog or CustomLog directive
7d15331eeb5429d7148d13d6fd914a641bf1c000pquerna * appears in the VirtualHost section, the log files defined outside
36488004520b3a22fbd37ef8e10e5641be154ac1slive * the VirtualHost will _not_ be used. This makes this module compatable
36488004520b3a22fbd37ef8e10e5641be154ac1slive * with the CLF and config log modules, where the use of TransferLog
36488004520b3a22fbd37ef8e10e5641be154ac1slive * inside the VirtualHost section overrides its use outside.
36488004520b3a22fbd37ef8e10e5641be154ac1slive * Examples:
36488004520b3a22fbd37ef8e10e5641be154ac1slive * TransferLog logs/access_log
36488004520b3a22fbd37ef8e10e5641be154ac1slive * <VirtualHost>
36488004520b3a22fbd37ef8e10e5641be154ac1slive * LogFormat "... custom format ..."
36488004520b3a22fbd37ef8e10e5641be154ac1slive * TransferLog log/virtual_only
36488004520b3a22fbd37ef8e10e5641be154ac1slive * CustomLog log/virtual_useragents "%t %{user-agent}i"
36488004520b3a22fbd37ef8e10e5641be154ac1slive * </VirtualHost>
36488004520b3a22fbd37ef8e10e5641be154ac1slive * This will log using CLF to access_log any requests handled by the
36488004520b3a22fbd37ef8e10e5641be154ac1slive * main server, while any requests to the virtual host will be logged
36488004520b3a22fbd37ef8e10e5641be154ac1slive * with the "... custom format..." to virtual_only _AND_ using
36488004520b3a22fbd37ef8e10e5641be154ac1slive * the custom user-agent log to virtual_useragents.
36488004520b3a22fbd37ef8e10e5641be154ac1slive * Note that the NCSA referer and user-agent logs are easily added with
36488004520b3a22fbd37ef8e10e5641be154ac1slive * CustomLog:
96aee4c18ac74113f91235b99233431769cd1e31jsl * CustomLog logs/referer "%{referer}i -> %U"
b47bddbe88fb1489893591d69d4ccab9b873af68humbedooh * CustomLog logs/agent "%{user-agent}i"
b47bddbe88fb1489893591d69d4ccab9b873af68humbedooh * RefererIgnore functionality can be obtained with conditional
b47bddbe88fb1489893591d69d4ccab9b873af68humbedooh * logging (SetEnvIf and CustomLog ... env=!VAR).
36488004520b3a22fbd37ef8e10e5641be154ac1slive * But using this method allows much easier modification of the
36488004520b3a22fbd37ef8e10e5641be154ac1slive * log format, e.g. to log hosts along with UA:
36488004520b3a22fbd37ef8e10e5641be154ac1slive * CustomLog logs/referer "%{referer}i %U %h"
96aee4c18ac74113f91235b99233431769cd1e31jsl * The argument to LogFormat and CustomLog is a string, which can include
36488004520b3a22fbd37ef8e10e5641be154ac1slive * literal characters copied into the log files, and '%' directives as
36488004520b3a22fbd37ef8e10e5641be154ac1slive * %...B: bytes sent, excluding HTTP headers.
36488004520b3a22fbd37ef8e10e5641be154ac1slive * %...b: bytes sent, excluding HTTP headers in CLF format, i.e. a '-'
36488004520b3a22fbd37ef8e10e5641be154ac1slive * when no bytes where sent (rather than a '0'.
36488004520b3a22fbd37ef8e10e5641be154ac1slive * %...c: Status of the connection.
36488004520b3a22fbd37ef8e10e5641be154ac1slive * 'X' = connection aborted before the response completed.
36488004520b3a22fbd37ef8e10e5641be154ac1slive * '+' = connection may be kept alive after the response is sent.
36488004520b3a22fbd37ef8e10e5641be154ac1slive * '-' = connection will be closed after the response is sent.
36488004520b3a22fbd37ef8e10e5641be154ac1slive * %...{FOOBAR}C: The contents of the HTTP cookie FOOBAR
b47bddbe88fb1489893591d69d4ccab9b873af68humbedooh * %...{FOOBAR}e: The contents of the environment variable FOOBAR
1f1b6bf13313fdd14a45e52e553d3ff28689b717coar * %...f: filename
b47bddbe88fb1489893591d69d4ccab9b873af68humbedooh * %...h: remote host
b47bddbe88fb1489893591d69d4ccab9b873af68humbedooh * %...a: remote IP-address
b47bddbe88fb1489893591d69d4ccab9b873af68humbedooh * %...A: local IP-address
96aee4c18ac74113f91235b99233431769cd1e31jsl * %...{Foobar}i: The contents of Foobar: header line(s) in the request
36488004520b3a22fbd37ef8e10e5641be154ac1slive * sent to the client.
36488004520b3a22fbd37ef8e10e5641be154ac1slive * %...l: remote logname (from identd, if supplied)
36488004520b3a22fbd37ef8e10e5641be154ac1slive * %...{Foobar}n: The contents of note "Foobar" from another module.
36488004520b3a22fbd37ef8e10e5641be154ac1slive * %...{Foobar}o: The contents of Foobar: header line(s) in the reply.
36488004520b3a22fbd37ef8e10e5641be154ac1slive * %...p: the port the request was served to
36488004520b3a22fbd37ef8e10e5641be154ac1slive * %...P: the process ID of the child that serviced the request.
36488004520b3a22fbd37ef8e10e5641be154ac1slive * %...r: first line of request
36488004520b3a22fbd37ef8e10e5641be154ac1slive * %...s: status. For requests that got internally redirected, this
36488004520b3a22fbd37ef8e10e5641be154ac1slive * is status of the *original* request --- %...>s for the last.
083c5339583e94bf811cf61bdbc1dbc6a382a89edpejesh * %...t: time, in common log format time format
b47bddbe88fb1489893591d69d4ccab9b873af68humbedooh * %...{format}t: The time, in the form given by format, which should
083c5339583e94bf811cf61bdbc1dbc6a382a89edpejesh * be in strftime(3) format.
b47bddbe88fb1489893591d69d4ccab9b873af68humbedooh * %...T: the time taken to serve the request, in seconds.
36488004520b3a22fbd37ef8e10e5641be154ac1slive * %...u: remote user (from auth; may be bogus if return status (%s) is 401)
36488004520b3a22fbd37ef8e10e5641be154ac1slive * %...U: the URL path requested.
36488004520b3a22fbd37ef8e10e5641be154ac1slive * %...v: the configured name of the server (i.e. which virtual host?)
36488004520b3a22fbd37ef8e10e5641be154ac1slive * %...V: the server name according to the UseCanonicalName setting
36488004520b3a22fbd37ef8e10e5641be154ac1slive * %...m: the request method
36488004520b3a22fbd37ef8e10e5641be154ac1slive * %...H: the request protocol
36488004520b3a22fbd37ef8e10e5641be154ac1slive * %...q: the query string prepended by "?", or empty if no query string
36488004520b3a22fbd37ef8e10e5641be154ac1slive * The '...' can be nothing at all (e.g. "%h %u %r %s %b"), or it can
36488004520b3a22fbd37ef8e10e5641be154ac1slive * indicate conditions for inclusion of the item (which will cause it
36488004520b3a22fbd37ef8e10e5641be154ac1slive * to be replaced with '-' if the condition is not met). Note that
#include "apr_strings.h"
#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_log.h"
#include "http_protocol.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#ifdef HAVE_LIMITS_H
#include <limits.h>
#ifdef HAVE_STRINGS_H
#include <strings.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
static void register_hooks(void)