coar 99/03/04 21:24:30
Modified: pthreads/htdocs/manual/mod mod_log_config.html pthreads/src/modules/standard mod_log_config.c Log: Bring over the recent changes to mod_log_config in 1.3. Revision Changes Path 1.29 +83 -10 apache-apr/pthreads/htdocs/manual/mod/mod_log_config.html Index: mod_log_config.html =================================================================== RCS file: /home/cvs/apache-apr/pthreads/htdocs/manual/mod/mod_log_config.html,v retrieving revision 1.28 retrieving revision 1.29 diff -u -r1.28 -r1.29 --- mod_log_config.html 1998/09/17 12:33:07 1.28 +++ mod_log_config.html 1999/03/05 05:24:29 1.29 @@ -14,22 +14,23 @@ > <!--#include virtual="header.html" --> <H1 ALIGN="CENTER">Module mod_log_config</H1> - +<P> This module is contained in the <CODE>mod_log_config.c</CODE> file, and is compiled in by default in Apache 1.2. mod_log_config replaces mod_log_common in Apache 1.2. Prior to version 1.2, mod_log_config was an optional module. It provides for logging of the requests made to the server, using the Common Log Format or a user-specified format. +</P> <H2>Summary</H2> - +<P> Three directives are provided by this module: <CODE>TransferLog</CODE> to create a log file, <CODE>LogFormat</CODE> to set a custom format, and <CODE>CustomLog</CODE> to define a log file and format in one go. The <CODE>TransferLog</CODE> and <CODE>CustomLog</CODE> directives can be used multiple times in each server to cause each request to be logged to multiple files. -<P> +</P> <H3>Compatibility notes</H3> @@ -45,6 +46,20 @@ <CODE>CookieLog</CODE> is deprecated, and a <CODE>CustomLog</CODE> should be defined to log user-tracking information instead. +<LI>As of Apache 1.3.5, this module allows conditional logging +based upon the setting of environment variables. That is, +you can control whether a request should be logged or not +based upon whether an arbitrary environment variable is +defined or not. This is settable on a <EM>per</EM>-logfile +basis. + +<LI>Beginning with Apache 1.3.5, the mod_log_config module has +also subsumed the <CODE>RefererIgnore</CODE> functionality from +<A HREF="mod_log_referer.html">mod_log_referer</A>. The effect +of <CODE>RefererIgnore</CODE> can be achieved by combinations of +<A HREF="mod_setenvif.html"><CODE>SetEnvIf</CODE></A> directives +and conditional <CODE>CustomLog</CODE> definitions. + </UL> <H2>Log File Formats</H2> @@ -128,6 +143,7 @@ %...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. </PRE> The `...' can be nothing at all (<EM>e.g.</EM>, <CODE>"%h %u %r %s %b"</CODE>), or it can @@ -195,6 +211,7 @@ <UL> <LI><A HREF="#cookielog">CookieLog</A> <LI><A HREF="#customlog">CustomLog</A> +<LI><A HREF="#customlog-conditional">CustomLog (conditional)</A> <LI><A HREF="#logformat">LogFormat</A> <LI><A HREF="#transferlog">TransferLog</A> </UL> @@ -223,8 +240,8 @@ The CookieLog directive sets the filename for logging of cookies. The filename is relative to the <A HREF="core.html#serverroot">ServerRoot</A>. This directive is included -only for compatibility with <A -HREF="mod_cookies.html">mod_cookies</A>, and is deprecated. +only for compatibility with +<A HREF="mod_cookies.html">mod_cookies</A>, and is deprecated. <P> <HR> @@ -242,7 +259,10 @@ HREF="directive-dict.html#Status" REL="Help" ><STRONG>Status:</STRONG></A> Base<BR> -<STRONG>Compatibility: </STRONG> Nickname only available in Apache 1.3 +<A + HREF="directive-dict.html#Compatibility" + REL="Help" +><STRONG>Compatibility:</STRONG></A> Nickname only available in Apache 1.3 or later <BR> <A @@ -274,7 +294,58 @@ ><SAMP>LogFormat</SAMP></A> directive. </P> + <HR> +<H2><A NAME="customlog-conditional">CustomLog (conditional)</A></H2> +<A + HREF="directive-dict.html#Syntax" + REL="Help" +><STRONG>Syntax:</STRONG></A> CustomLog <EM>file-pipe</EM> + <EM>format-or-nickname</EM> + env=[!]<EM>environment-variable</EM><BR> +<A + HREF="directive-dict.html#Context" + REL="Help" +><STRONG>Context:</STRONG></A> server config, virtual host<BR> +<A + HREF="directive-dict.html#Status" + REL="Help" +><STRONG>Status:</STRONG></A> Base<BR> +<A + HREF="directive-dict.html#Compatibility" + REL="Help" +><STRONG>Compatibility:</STRONG></A> Only available in Apache 1.3.5 + or later +<BR> +<A + HREF="directive-dict.html#Module" + REL="Help" +><STRONG>Module:</STRONG></A> mod_log_config +<P> + +The behaviour of this form of the <SAMP>CustomLog</SAMP> directive is almost +identical to the <A HREF="#customlog">standard <CODE>CustomLog</CODE></A> +directive. The difference is that the '<CODE>env=</CODE>' clause controls +whether a particular request will be logged in the specified file or +not. If the specified environment variable is set for the +request (or is not set, in the case of a '<CODE>env=!<EM>name</EM></CODE>' +clause), then the request will be logged. +</P> +<P> +Environment variables can be set on a <EM>per</EM>-request basis +using the <A HREF="mod_setenvif.html">mod_setenvif</A> and/or +<A HREF="mod_rewrite.html">mod_rewrite</A> modules. For example, +if you don't want to record requests for all GIF images on +your server in a separate logfile but not your main log, you +can use: +</P> +<PRE> + SetEnvIf Request_URI \.gif$ gif-image + CustomLog gif-requests.log common env=gif-image + CustomLog nongif-requests.log common env=!gif-image +</PRE> + +<HR> <H2><A NAME="logformat">LogFormat</A></H2> <!--%plaintext <?INDEX {\tt LogFormat} directive> --> <A @@ -295,7 +366,10 @@ HREF="directive-dict.html#Status" REL="Help" ><STRONG>Status:</STRONG></A> Base<BR> -<STRONG>Compatibility: </STRONG> Nickname only available in Apache 1.3 +<A + HREF="directive-dict.html#Compatibility" + REL="Help" +><STRONG>Compatibility:</STRONG></A> Nickname only available in Apache 1.3 or later <BR> <A @@ -314,9 +388,7 @@ <P> If you include a nickname for the format on the directive line, you can use it in other <SAMP>LogFormat</SAMP> and -<A - HREF="#customlog" -><SAMP>CustomLog</SAMP></A> +<A HREF="#customlog"><SAMP>CustomLog</SAMP></A> directives rather than repeating the entire format string. </P> <P> @@ -327,6 +399,7 @@ </P> <HR> + <H2><A NAME="transferlog">TransferLog</A></H2> <!--%plaintext <?INDEX {\tt TransferLog} directive> --> <A 1.3 +108 -27 apache-apr/pthreads/src/modules/standard/mod_log_config.c Index: mod_log_config.c =================================================================== RCS file: /home/cvs/apache-apr/pthreads/src/modules/standard/mod_log_config.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- mod_log_config.c 1999/02/07 06:29:54 1.2 +++ mod_log_config.c 1999/03/05 05:24:30 1.3 @@ -106,8 +106,8 @@ * CustomLog logs/referer "%{referer}i -> %U" * CustomLog logs/agent "%{user-agent}i" * - * Except: no RefererIgnore functionality - * logs '-' if no Referer or User-Agent instead of nothing + * 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: @@ -138,7 +138,8 @@ * %...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 name of the server (i.e. which virtual host?) + * %...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 @@ -235,6 +236,7 @@ char *format_string; array_header *format; int log_fd; + char *condition_var; #ifdef BUFFERED_LOGS int outcnt; char outbuf[LOG_BUFSIZE]; @@ -416,6 +418,14 @@ r->server->port ? r->server->port : ap_default_port(r)); } +/* 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) { return ap_psprintf(r->pool, "%ld", (long) getpid()); @@ -478,6 +488,9 @@ 'e', log_env_var, 0 }, { + 'V', log_server_name, 0 + }, + { 'v', log_virtual_host, 0 }, { @@ -503,30 +516,61 @@ return NULL; } -static char *log_format_substring(pool *p, const char *start, - const char *end) -{ - char *res = ap_palloc(p, end - start + 1); - - strncpy(res, start, end - start); - res[end - start] = '\0'; - return res; -} - static char *parse_log_misc_string(pool *p, log_format_item *it, const char **sa) { - const char *s = *sa; + const char *s; + char *d; it->func = constant_item; it->conditions = NULL; + s = *sa; while (*s && *s != '%') { - ++s; + s++; } - it->arg = log_format_substring(p, *sa, s); - *sa = s; + /* + * This might allocate a few chars extra if there's a backslash + * escape in the format string. + */ + it->arg = ap_palloc(p, s - *sa + 1); + d = it->arg; + 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; } @@ -689,11 +733,30 @@ int i; int len = 0; array_header *format; + char *envar; if (cls->fname == NULL) { return DECLINED; } + /* + * See if we've got any conditional envariable-controlled logging decisions + * to make. + */ + if (cls->condition_var != NULL) { + envar = cls->condition_var; + if (*envar != '!') { + if (ap_table_get(r->subprocess_env, envar) == NULL) { + return DECLINED; + } + } + else { + if (ap_table_get(r->subprocess_env, &envar[1]) != NULL) { + return DECLINED; + } + } + } + format = cls->format ? cls->format : default_format; strs = ap_palloc(r->pool, sizeof(char *) * (format->nelts)); @@ -752,10 +815,13 @@ static int multi_log_transaction(request_rec *r) { multi_log_state *mls = ap_get_module_config(r->server->module_config, - &config_log_module); + &config_log_module); config_log_state *clsarray; int i; + /* + * Log this transaction.. + */ if (mls->config_logs->nelts) { clsarray = (config_log_state *) mls->config_logs->elts; for (i = 0; i < mls->config_logs->nelts; ++i) { @@ -783,8 +849,9 @@ static void *make_config_log_state(pool *p, server_rec *s) { - multi_log_state *mls = (multi_log_state *) ap_palloc(p, sizeof(multi_log_state)); + multi_log_state *mls; + mls = (multi_log_state *) ap_palloc(p, sizeof(multi_log_state)); mls->config_logs = ap_make_array(p, 1, sizeof(config_log_state)); mls->default_format_string = NULL; mls->default_format = NULL; @@ -824,7 +891,7 @@ { const char *err_string = NULL; multi_log_state *mls = ap_get_module_config(cmd->server->module_config, - &config_log_module); + &config_log_module); /* * If we were given two arguments, the second is a name to be given to the @@ -844,18 +911,31 @@ return err_string; } + static const char *add_custom_log(cmd_parms *cmd, void *dummy, char *fn, - char *fmt) + char *fmt, char *envclause) { const char *err_string = NULL; multi_log_state *mls = ap_get_module_config(cmd->server->module_config, - &config_log_module); + &config_log_module); config_log_state *cls; cls = (config_log_state *) ap_push_array(mls->config_logs); + cls->condition_var = NULL; + if (envclause != NULL) { + if (strncasecmp(envclause, "env=", 4) != 0) { + return "error in condition clause"; + } + if ((envclause[4] == '\0') + || ((envclause[4] == '!') && (envclause[5] == '\0'))) { + return "missing environment variable name"; + } + cls->condition_var = ap_pstrdup(cmd->pool, &envclause[4]); + } + cls->fname = fn; cls->format_string = fmt; - if (!fmt) { + if (fmt == NULL) { cls->format = NULL; } else { @@ -868,18 +948,19 @@ static const char *set_transfer_log(cmd_parms *cmd, void *dummy, char *fn) { - return add_custom_log(cmd, dummy, fn, NULL); + return add_custom_log(cmd, dummy, fn, NULL, NULL); } static const char *set_cookie_log(cmd_parms *cmd, void *dummy, char *fn) { - return add_custom_log(cmd, dummy, fn, "%{Cookie}n \"%r\" %t"); + return add_custom_log(cmd, dummy, fn, "%{Cookie}n \"%r\" %t", NULL); } static const command_rec config_log_cmds[] = { - {"CustomLog", add_custom_log, NULL, RSRC_CONF, TAKE2, - "a file name and a custom log format string or format name"}, + {"CustomLog", add_custom_log, NULL, RSRC_CONF, TAKE23, + "a file name, a custom log format string or format name, " + "and an optional \"env=\" clause (see docs)"}, {"TransferLog", set_transfer_log, NULL, RSRC_CONF, TAKE1, "the filename of the access log"}, {"LogFormat", log_format, NULL, RSRC_CONF, TAKE12,