mod_log_config.c revision 3a9bc6532fbe8439fc748d8ffedb87415904d16a
/* ====================================================================
* Copyright (c) 1995-2000 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the Apache Software Foundation
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* 4. The names "Apache Server" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the Apache Software Foundation
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* THIS SOFTWARE IS PROVIDED BY THE Apache Software Foundation ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE Apache Software Foundation OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was originally based
* on public domain software written at the National Center for
* Supercomputing Applications, University of Illinois, Urbana-Champaign.
* For more information on the Apache Software Foundation and the Apache HTTP server
* project, please see <http://www.apache.org/>.
*
*/
/*
* Modified by djm@va.pubnix.com:
* If no TransferLog is given explicitly, decline to log.
*
* This is module implements the TransferLog directive (same as the
* common log module), and additional directives, LogFormat and CustomLog.
*
*
* Syntax:
*
* TransferLog fn Logs transfers to fn in standard log format, unless
* a custom format is set with LogFormat
* LogFormat format Set a log format from TransferLog files
* CustomLog fn format
* Log to file fn with format given by the format
* argument
*
* CookieLog fn For backwards compatability with old Cookie
* logging module - now deprecated.
*
* There can be any number of TransferLog and CustomLog
* commands. Each request will be logged to _ALL_ the
* named files, in the appropriate format.
*
* If no TransferLog or CustomLog directive appears in a VirtualHost,
* the request will be logged to the log file(s) defined outside
* the virtual host section. If a TransferLog or CustomLog directive
* appears in the VirtualHost section, the log files defined outside
* the VirtualHost will _not_ be used. This makes this module compatable
* with the CLF and config log modules, where the use of TransferLog
* inside the VirtualHost section overrides its use outside.
*
* Examples:
*
* TransferLog logs/access_log
* <VirtualHost>
* LogFormat "... custom format ..."
* TransferLog log/virtual_only
* CustomLog log/virtual_useragents "%t %{user-agent}i"
* </VirtualHost>
*
* This will log using CLF to access_log any requests handled by the
* main server, while any requests to the virtual host will be logged
* with the "... custom format..." to virtual_only _AND_ using
* the custom user-agent log to virtual_useragents.
*
* Note that the NCSA referer and user-agent logs are easily added with
* CustomLog:
*
* RefererIgnore functionality can be obtained with conditional
* logging (SetEnvIf and CustomLog ... env=!VAR).
*
* But using this method allows much easier modification of the
* log format, e.g. to log hosts along with UA:
*
* The argument to LogFormat and CustomLog is a string, which can include
* literal characters copied into the log files, and '%' directives as
* follows:
*
* %...b: bytes sent, excluding HTTP headers.
* %...{FOOBAR}e: The contents of the environment variable FOOBAR
* %...f: filename
* %...h: remote host
* %...a: remote IP-address
* %...A: local IP-address
* %...{Foobar}i: The contents of Foobar: header line(s) in the request
* sent to the client.
* %...l: remote logname (from identd, if supplied)
* %...{Foobar}n: The contents of note "Foobar" from another module.
* %...{Foobar}o: The contents of Foobar: header line(s) in the reply.
* %...p: the port the request was served to
* %...P: the process ID of the child that serviced the request.
* %...r: first line of request
* %...s: status. For requests that got internally redirected, this
* is status of the *original* request --- %...>s for the last.
* %...t: time, in common log format time format
* %...{format}t: The time, in the form given by format, which should
* be in strftime(3) format.
* %...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 configured name of the server (i.e. which virtual host?)
* %...V: the server name according to the UseCanonicalName setting
*
* The '...' can be nothing at all (e.g. "%h %u %r %s %b"), or it can
* indicate conditions for inclusion of the item (which will cause it
* to be replaced with '-' if the condition is not met). Note that
* there is no escaping performed on the strings from %r, %...i and
* %...o; some with long memories may remember that I thought this was
* a bad idea, once upon a time, and I'm still not comfortable with
* it, but it is difficult to see how to "do the right thing" with all
* of '%..i', unless we URL-escape everything and break with CLF.
*
* The forms of condition are a list of HTTP status codes, which may
* or may not be preceded by '!'. Thus, '%400,501{User-agent}i' logs
* User-agent: on 400 errors and 501 errors (Bad Request, Not
* Implemented) only; '%!200,304,302{Referer}i' logs Referer: on all
* requests which did *not* return some sort of normal status.
*
* The default LogFormat reproduces CLF; see below.
*
* The way this is supposed to work with virtual hosts is as follows:
* a virtual host can have its own LogFormat, or its own TransferLog.
* If it doesn't have its own LogFormat, it inherits from the main
* server. If it doesn't have its own TransferLog, it writes to the
* same descriptor (meaning the same process for "| ...").
*
* --- rst */
#define DEFAULT_LOG_FORMAT "%h %l %u %t \"%r\" %>s %b"
#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_core.h" /* For REMOTE_NAME */
#include "http_log.h"
#include "http_protocol.h"
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
/* OS/2 dosen't support users and groups */
#else
#endif
/* POSIX.1 defines PIPE_BUF as the maximum number of bytes that is
* guaranteed to be atomic when writing a pipe. And PIPE_BUF >= 512
* is guaranteed. So we'll just guess 512 in the event the system
* doesn't have this. Now, for file writes there is actually no limit,
* the entire write is atomic. Whether all systems implement this
* correctly is another question entirely ... so we'll just use PIPE_BUF
* because it's probably a good guess as to what is implemented correctly
* everywhere.
*/
#ifdef PIPE_BUF
#define LOG_BUFSIZE PIPE_BUF
#else
#define LOG_BUFSIZE (512)
#endif
/*
* multi_log_state is our per-(virtual)-server configuration. We store
* an array of the logs we are going to use, each of type config_log_state.
* If a default log format is given by LogFormat, store in default_format
* (backward compat. with mod_log_config). We also store for each virtual
* server a pointer to the logs specified for the main server, so that if this
* vhost has no logs defined, we can use the main server's logs instead.
*
* So, for the main server, config_logs contains a list of the log files
* and server_config_logs in empty. For a vhost, server_config_logs
* points to the same array as config_logs in the main server, and
* config_logs points to the array of logs defined inside this vhost,
* which might be empty.
*/
typedef struct {
char *default_format_string;
/*
* config_log_state holds the status of a single log file. fname might
* be NULL, which means this module does no logging for this
* request. format might be NULL, in which case the default_format
* from the multi_log_state should be used, or if that is NULL as
* well, use the CLF. log_fd is NULL before the log file is opened and
* set to a valid fd after it is opened.
*/
typedef struct {
char *fname;
char *format_string;
char *condition_var;
#ifdef BUFFERED_LOGS
int outcnt;
char outbuf[LOG_BUFSIZE];
#endif
/*
* Format items...
* Note that many of these could have ap_sprintfs replaced with static buffers.
*/
typedef const char *(*item_key_func) (request_rec *, char *);
typedef struct {
char *arg;
int condition_sense;
int want_orig;
static char *format_integer(ap_context_t *p, int i)
{
return ap_psprintf(p, "%d", i);
}
static char *pfmt(ap_context_t *p, int i)
{
if (i <= 0) {
return "-";
}
else {
return format_integer(p, i);
}
}
{
return stuff;
}
static const char *log_remote_host(request_rec *r, char *a)
{
}
static const char *log_remote_address(request_rec *r, char *a)
{
return r->connection->remote_ip;
}
static const char *log_local_address(request_rec *r, char *a)
{
return r->connection->local_ip;
}
static const char *log_remote_logname(request_rec *r, char *a)
{
return ap_get_remote_logname(r);
}
static const char *log_remote_user(request_rec *r, char *a)
{
rvalue = "-";
}
rvalue = "\"\"";
}
return rvalue;
}
static const char *log_request_line(request_rec *r, char *a)
{
/* NOTE: If the original request contained a password, we
* re-write the request line here to contain XXXXXX instead:
* (note the truncation before the protocol string for HTTP/0.9 requests)
* (note also that r->the_request contains the unmodified request)
*/
: r->the_request;
}
static const char *log_request_file(request_rec *r, char *a)
{
return r->filename;
}
static const char *log_request_uri(request_rec *r, char *a)
{
return r->uri;
}
static const char *log_status(request_rec *r, char *a)
{
}
static const char *log_bytes_sent(request_rec *r, char *a)
{
if (!r->sent_bodyct) {
return "-";
}
else {
long int bs;
}
}
static const char *log_header_in(request_rec *r, char *a)
{
return ap_table_get(r->headers_in, a);
}
static const char *log_header_out(request_rec *r, char *a)
{
}
if (cp) {
return cp;
}
return ap_table_get(r->err_headers_out, a);
}
static const char *log_note(request_rec *r, char *a)
{
return ap_table_get(r->notes, a);
}
static const char *log_env_var(request_rec *r, char *a)
{
return ap_table_get(r->subprocess_env, a);
}
static const char *log_request_time(request_rec *r, char *a)
{
char tstr[MAX_STRING_LEN];
/*
hi. i think getting the time again at the end of the request
just for logging is dumb. i know it's "required" for CLF.
folks writing log parsing tools don't realise that out of order
times have always been possible (consider what happens if one
process calculates the time to log, but then there's a context
switch before it writes and before that process is run again the
log rotation occurs) and they should just fix their tools rather
than force the server to pay extra cpu cycles. if you've got
a problem with this, you can set the define. -djg
*/
#else
#endif
if (a && *a) { /* Custom format */
}
else { /* CLF format */
char sign;
int timz;
if (timz < 0) {
sign = '-';
}
else {
sign = '+';
}
}
}
static const char *log_request_duration(request_rec *r, char *a)
{
}
/* These next two routines use the canonical name:port so that log
* parsers don't need to duplicate all the vhost parsing crud.
*/
static const char *log_virtual_host(request_rec *r, char *a)
{
return r->server->server_hostname;
}
static const char *log_server_port(request_rec *r, char *a)
{
}
/* This respects the setting of UseCanonicalName so that
* the dynamic mass virtual hosting trick works better.
*/
static const char *log_server_name(request_rec *r, char *a)
{
return ap_get_server_name(r);
}
static const char *log_child_pid(request_rec *r, char *a)
{
}
/*****************************************************************
*
* Parsing the log format string
*/
static struct log_item_list {
char ch;
int want_orig_default;
} log_item_keys[] = {
{
'h', log_remote_host, 0
},
{
'a', log_remote_address, 0
},
{
'A', log_local_address, 0
},
{
'l', log_remote_logname, 0
},
{
'u', log_remote_user, 0
},
{
't', log_request_time, 0
},
{
},
{
},
{
'f', log_request_file, 0
},
{
},
{
},
{
'b', log_bytes_sent, 0
},
{
'i', log_header_in, 0
},
{
'o', log_header_out, 0
},
{
'n', log_note, 0
},
{
'e', log_env_var, 0
},
{
'V', log_server_name, 0
},
{
'v', log_virtual_host, 0
},
{
'p', log_server_port, 0
},
{
'P', log_child_pid, 0
},
{
'\0'
}
};
static struct log_item_list *find_log_func(char k)
{
int i;
for (i = 0; log_item_keys[i].ch; ++i)
if (k == log_item_keys[i].ch) {
return &log_item_keys[i];
}
return NULL;
}
const char **sa)
{
const char *s;
char *d;
s = *sa;
while (*s && *s != '%') {
s++;
}
/*
* This might allocate a few chars extra if there's a backslash
* escape in the format string.
*/
s = *sa;
while (*s && *s != '%') {
if (*s != '\\') {
*d++ = *s++;
}
else {
s++;
switch (*s) {
case '\\':
*d++ = '\\';
s++;
break;
case 'n':
*d++ = '\n';
s++;
break;
case 't':
*d++ = '\t';
s++;
break;
default:
/* copy verbatim */
*d++ = '\\';
/*
* Allow the loop to deal with this *s in the normal
* fashion so that it handles end of string etc.
* properly.
*/
break;
}
}
}
*d = '\0';
*sa = s;
return NULL;
}
{
const char *s = *sa;
if (*s != '%') {
}
++s;
it->condition_sense = 0;
while (*s) {
int i;
struct log_item_list *l;
switch (*s) {
case '!':
++s;
break;
case '<':
++s;
break;
case '>':
++s;
break;
case ',':
++s;
break;
case '{':
++s;
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
i = *s - '0';
while (ap_isdigit(*++s)) {
i = i * 10 + (*s) - '0';
}
if (!it->conditions) {
}
break;
default:
l = find_log_func(*s++);
if (!l) {
char dummy[2];
dummy[0] = s[-1];
return ap_pstrcat(p, "Unrecognized LogFormat directive %",
}
}
*sa = s;
return NULL;
}
}
return "Ran off end of LogFormat parsing args to some directive";
}
{
char *res;
while (*s) {
return NULL;
}
}
s = "\n";
return a;
}
/*****************************************************************
*
* Actually logging.
*/
{
const char *cp;
/* First, see if we need to process this thing at all... */
int i;
int in_list = 0;
in_list = 1;
break;
}
}
return "-";
}
}
/* We do. Do it... */
}
#ifdef BUFFERED_LOGS
{
}
}
#endif
{
char *str, *s;
const char **strs;
int *strl;
int i;
ap_ssize_t len = 0;
char *envar;
return DECLINED;
}
/*
* See if we've got any conditional envariable-controlled logging decisions
* to make.
*/
if (*envar != '!') {
return DECLINED;
}
}
else {
return DECLINED;
}
}
}
orig = r;
}
while (r->next) {
r = r->next;
}
}
}
#ifdef BUFFERED_LOGS
}
if (len >= LOG_BUFSIZE) {
s += strl[i];
}
}
else {
s += strl[i];
}
}
#else
s += strl[i];
}
#endif
return OK;
}
static int multi_log_transaction(request_rec *r)
{
int i;
/*
* Log this transaction..
*/
}
}
else if (mls->server_config_logs) {
}
}
return OK;
}
/*****************************************************************
*
* Module glue...
*/
{
return mls;
}
/*
* Use the merger to simply add a pointer from the vhost log state
* to the log of logs specified for the non-vhost configuration. Make sure
* vhosts inherit any globally-defined format names.
*/
{
if (!add->default_format) {
}
return add;
}
/*
* Set the default logfile format, or define a nickname for a format string.
*/
char *name)
{
const char *err_string = NULL;
/*
* If we were given two arguments, the second is a name to be given to the
* format. This syntax just defines the nickname - it doesn't actually
* make the format the default.
*/
if (err_string == NULL) {
}
}
else {
}
return err_string;
}
{
const char *err_string = NULL;
return "error in condition clause";
}
return "missing environment variable name";
}
}
}
else {
}
return err_string;
}
{
}
{
}
static const command_rec config_log_cmds[] =
{
"a file name, a custom log format string or format name, "
"and an optional \"env=\" clause (see docs)"},
"the filename of the access log"},
"a log format string (see docs) and an optional format name"},
"the filename of the cookie log"},
{NULL}
};
{
}
return cls; /* Leave it NULL to decline. */
}
exit(1);
}
}
else {
!= APR_SUCCESS) {
"could not open transfer log file %s.", fname);
exit(1);
}
}
#ifdef BUFFERED_LOGS
#endif
return cls;
}
{
int i;
const char *dummy;
const char *format;
if (mls->default_format_string) {
if (format) {
}
}
if (!mls->default_format) {
}
if (cls->format_string) {
if (format) {
}
}
}
}
else if (mls->server_config_logs) {
if (cls->format_string) {
if (format) {
}
}
}
}
return NULL;
}
{
/* First, do "physical" server, which gets default log fd and format
* for the virtual servers, if they don't override...
*/
open_multi_logs(s, p);
/* Then, virtual servers */
open_multi_logs(s, p);
}
#ifdef BUFFERED_LOGS
/* Now register the last buffer flush with the cleanup engine */
#endif
}
#ifdef BUFFERED_LOGS
static void flush_all_logs(server_rec *s)
{
int i;
for (; s; s = s->next) {
}
else if (mls->server_config_logs) {
}
if (log_list) {
}
}
}
}
#endif
static void register_hooks(void)
{
}
{
NULL, /* create per-dir config */
NULL, /* merge per-dir config */
make_config_log_state, /* server config */
merge_config_log_state, /* merge server config */
config_log_cmds, /* command ap_table_t */
NULL, /* handlers */
register_hooks /* register hooks */
};