Return-Path: Delivered-To: apache-cvs-archive@hyperreal.org Received: (qmail 21681 invoked by uid 6000); 17 Feb 1999 23:28:26 -0000 Received: (qmail 21618 invoked by alias); 17 Feb 1999 23:28:22 -0000 Delivered-To: apache-1.3-cvs@hyperreal.org Received: (qmail 21584 invoked by uid 161); 17 Feb 1999 23:28:21 -0000 Date: 17 Feb 1999 23:28:21 -0000 Message-ID: <19990217232821.21583.qmail@hyperreal.org> From: coar@hyperreal.org To: apache-1.3-cvs@hyperreal.org Subject: cvs commit: apache-1.3/src/modules/standard mod_log_config.c Sender: apache-cvs-owner@apache.org Precedence: bulk Reply-To: new-httpd@apache.org coar 99/02/17 15:28:20 Modified: htdocs/manual/mod mod_log_config.html src CHANGES src/modules/standard mod_log_config.c Log: Add conditional logging based upon environment variable existence. Also add RefererIgnore functionality from mod_log_referer to mod_log_config; mod_log_referer and mod_log_agent are now deprecated. The list of envariables to check is set up as an array even though the current implementation (TAKE23) only handles one; just in case we ever want to do something strange like, 'env=foo,bar,!bag'. PR: 519, 548, 1351, 1811(?), 3449 Revision Changes Path 1.29 +133 -10 apache-1.3/htdocs/manual/mod/mod_log_config.html Index: mod_log_config.html =================================================================== RCS file: /home/cvs/apache-1.3/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/02/17 23:28:11 1.29 @@ -14,22 +14,23 @@ >

Module mod_log_config

- +

This module is contained in the mod_log_config.c 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. +

Summary

- +

Three directives are provided by this module: TransferLog to create a log file, LogFormat to set a custom format, and CustomLog to define a log file and format in one go. The TransferLog and CustomLog directives can be used multiple times in each server to cause each request to be logged to multiple files. -

+

Compatibility notes

@@ -45,6 +46,22 @@ CookieLog is deprecated, and a CustomLog should be defined to log user-tracking information instead. +
  • 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 per-logfile +basis. + +
  • Beginning with Apache 1.3.5, the mod_log_config module has +also subsumed the RefererIgnore directive from +mod_log_referer. The use +of RefererIgnore is deprecated, and should be +replaced by combinations of +SetEnvIf directives +and environment variable controlled CustomLog +definitions. +

    Log File Formats

    @@ -195,7 +212,9 @@
    @@ -223,8 +242,8 @@ The CookieLog directive sets the filename for logging of cookies. The filename is relative to the ServerRoot. This directive is included -only for compatibility with mod_cookies, and is deprecated. +only for compatibility with +mod_cookies, and is deprecated.


    @@ -242,7 +261,10 @@ HREF="directive-dict.html#Status" REL="Help" >Status: Base
    -Compatibility: Nickname only available in Apache 1.3 +Compatibility: Nickname only available in Apache 1.3 or later
    LogFormat directive.

    +
    +

    CustomLog (conditional)

    +Syntax: CustomLog file-pipe + format-or-nickname + env=[!]environment-variable
    +Context: server config, virtual host
    +Status: Base
    +Compatibility: Only available in Apache 1.3.5 + or later +
    +Module: mod_log_config +

    + +The behaviour of this form of the CustomLog directive is almost +identical to the standard CustomLog +directive. The difference is that the 'env=' 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 'env=!name' +clause), then the request will be logged. +

    +

    +Environment variables can be set on a per-request basis +using the mod_setenvif and/or +mod_rewrite 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: +

    +
      +    SetEnvIf Request_URI \.gif$ gif-image
      +    CustomLog gif-requests.log common env=gif-image
      +    CustomLog nongif-requests.log common env=!gif-image
      +
    + +

    LogFormat

    Status: Base
    -Compatibility: Nickname only available in Apache 1.3 +Compatibility: Nickname only available in Apache 1.3 or later
    If you include a nickname for the format on the directive line, you can use it in other LogFormat and -CustomLog +CustomLog directives rather than repeating the entire format string.

    @@ -327,6 +401,55 @@


    +

    RefererIgnore

    +Syntax: RefererIgnore string string ...
    +Context: server config, virtual host
    +Status: Base
    +Compatibility:> Only available in Apache 1.3.5 + or later +
    +Module: mod_log_config + +

    +The RefererIgnore directive adds to the list of strings to ignore in +Referer headers. If any of the strings in the list is contained in +the Referer header, then no referrer information will be logged for the +request. Example: +

    +
      +    RefererIgnore www.ncsa.uiuc.edu
      +
    +

    +will avoid logging references from www.ncsa.uiuc.edu. +

    +

    +Note: All transaction logfiles +(defined by CustomLog or TransferLog) in +the same server scope as the RefererIgnore (e.g., +in the same <VirtualHost> container) +are affected by +this directive. If you want to control this behaviour on a +per-logfile basis, you should use the +conditional CustomLog +capability. +

    +
    +

    TransferLog

    conditions != 0) { + char **candidates = (char **) cls->condition_list->elts; + for (i = 0; i < cls->condition_list->nelts; ++i) { + char *envname = candidates[i]; + if (*envname != '!') { + if (ap_table_get(r->subprocess_env, envname) == NULL) { + return DECLINED; + } + } + else { + if (ap_table_get(r->subprocess_env, &envname[1]) != NULL) { + return DECLINED; + } + } + } + } + format = cls->format ? cls->format : default_format; strs = ap_palloc(r->pool, sizeof(char *) * (format->nelts)); @@ -752,10 +777,27 @@ 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; + /* + * See if there are any Referer: values we're supposed to ignore. + */ + if (mls->ignore_referers != 0) { + const char *referer = ap_table_get(r->headers_in, "Referer"); + if (referer != NULL) { + char **candidate = (char **) mls->referer_list->elts; + for (i = 0; i < mls->referer_list->nelts; ++i) { + if (strstr(referer, candidate[i]) != NULL) { + return DECLINED; + } + } + } + } + /* + * Continue and 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,14 +825,17 @@ 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; mls->server_config_logs = NULL; mls->formats = ap_make_table(p, 4); ap_table_setn(mls->formats, "CLF", DEFAULT_LOG_FORMAT); + mls->ignore_referers = 0; + mls->referer_list = NULL; return mls; } @@ -812,6 +857,12 @@ add->default_format = base->default_format; } add->formats = ap_overlay_tables(p, base->formats, add->formats); + add->ignore_referers = (add->ignore_referers != 0) + ? add->ignore_referers + : base->ignore_referers; + if (base->ignore_referers != 0) { + ap_array_cat(add->referer_list, base->referer_list); + } return add; } @@ -824,7 +875,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 +895,47 @@ return err_string; } +static const char *add_referer_ignore(cmd_parms *cmd, void *mconfig, + char *word1) +{ + multi_log_state *mls = ap_get_module_config(cmd->server->module_config, + &config_log_module); + char **ignore_uri; + + mls->ignore_referers++; + if (mls->referer_list == NULL) { + mls->referer_list = ap_make_array(cmd->pool, 4, sizeof(char *)); + } + ignore_uri = (char **) ap_push_array(mls->referer_list); + *ignore_uri = ap_pstrdup(cmd->pool, word1); + return NULL; +} + 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->conditions = 0; + if (envclause != NULL) { + char **env_condition; + + if (strncasecmp(envclause, "env=", 4) != 0) { + return "error in condition clause"; + } + cls->condition_list = ap_make_array(cmd->pool, 4, sizeof(char *)); + env_condition = (char **) ap_push_array(cls->condition_list); + *env_condition = ap_pstrdup(cmd->pool, &envclause[4]); + cls->conditions++; + } + cls->fname = fn; cls->format_string = fmt; - if (!fmt) { + if (fmt != NULL) { cls->format = NULL; } else { @@ -868,24 +948,27 @@ 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, "a log format string (see docs) and an optional format name"}, {"CookieLog", set_cookie_log, NULL, RSRC_CONF, TAKE1, "the filename of the cookie log"}, + {"RefererIgnore", add_referer_ignore, NULL, RSRC_CONF, ITERATE, + "referer URLs to ignore"}, {NULL} };