Received: (from majordom@localhost) by hyperreal.org (8.8.5/8.8.5) id HAA24145; Fri, 15 Aug 1997 07:53:23 -0700 (PDT) Received: from DECUS.Org (Topaz.DECUS.Org [192.67.173.1]) by hyperreal.org (8.8.5/8.8.5) with ESMTP id HAA24140 for ; Fri, 15 Aug 1997 07:53:19 -0700 (PDT) Received: from Master.DECUS.Org (master.process.com) by DECUS.Org (PMDF V4.2-13 #18511) id <01IMGSGPR5W08WW4EI@DECUS.Org>; Fri, 15 Aug 1997 10:53:11 EDT Date: Fri, 15 Aug 1997 10:52:28 -0400 From: coar@decus.org (Rodent of Unusual Size) Subject: [PATCH] Disabling logging based on envariable To: New-HTTPd@apache.org, Coar@decus.org Message-id: <97081510522863@decus.org> X-VMS-To: NH X-VMS-Cc: COAR Content-transfer-encoding: 7BIT Sender: new-httpd-owner@apache.org Precedence: bulk Reply-To: new-httpd@apache.org A while ago I suggested that we rm mod_log_agent and mod_log_referer, but Rob pointed out that the latter had functionality that mod_log_config lacked: the ability to selectively *not* log based upon the value of the Referer header field. Okey, here's a patch to mod_log_config that addresses that and a whole lot more. It adds the "DoNotLogIf" directive, with the syntax DoNotLogIf env=some_envariable (I'm not happy with the directive name; suggestions welcome.) Combined with mod_setenvif, I think this is a *major* enhancement to the ability to tailor logging. Works for me.. anyone see problems before I commit to 1.3 in 48 hours? (lazy voting rules) #ken :-)} Index: mod_log_config.c =================================================================== RCS file: /export/home/cvs/apachen/src/modules/standard/mod_log_config.c,v retrieving revision 1.34 diff -u -r1.34 mod_log_config.c --- mod_log_config.c 1997/07/28 18:23:01 1.34 +++ mod_log_config.c 1997/08/15 14:48:03 @@ -192,6 +192,7 @@ array_header *default_format; array_header *config_logs; array_header *server_config_logs; + array_header *disabling_envs; } multi_log_state; /* @@ -209,6 +210,13 @@ } config_log_state; /* + * Incredibly simple record for remembering the name of an envariable. + */ +typedef struct { + char *name; +} env_rec; + +/* * Format items... */ @@ -568,6 +576,19 @@ config_log_state *clsarray; int i; + /* + * First things first. Walk through the array of envariables whose + * existence disable logging. If we find one in the request's envariable + * array, we just leave quietly. + */ + if (mls->disabling_envs != NULL) { + env_rec *envar = (env_rec *)mls->disabling_envs->elts; + for (i = 0; i < mls->disabling_envs->nelts; ++i) { + if (table_get (r->subprocess_env, (char *)envar[i].name) != NULL) { + return OK; + } + } + } if (mls->config_logs->nelts) { clsarray = (config_log_state *)mls->config_logs->elts; for (i = 0; i < mls->config_logs->nelts; ++i) { @@ -602,6 +623,7 @@ make_array(p, 5, sizeof (config_log_state)); mls->default_format = NULL; mls->server_config_logs = NULL; + mls->disabling_envs = NULL; return mls; } @@ -617,8 +639,9 @@ multi_log_state *add = (multi_log_state *)addv; add->server_config_logs = base->config_logs; - if (!add->default_format) + if (!add->default_format) { add->default_format = base->default_format; + } return add; } @@ -661,6 +684,29 @@ return add_custom_log(cmd, dummy, fn, "%{Cookie}n \"%r\" %t"); } +/* + * Make a note of an environment variable condition which will prevent + * logging. + */ +static const char *note_disabling_env(cmd_parms *cmd, void *mcfg, char *cond) +{ + multi_log_state *mls = + (multi_log_state *)get_module_config(cmd->server->module_config, + &config_log_module); + env_rec *envar; + + if (strncasecmp(cond, "env=", 4)) { + return pstrcat(cmd->pool, "Bad argument \"", cond, "\" to ", + cmd->cmd->name, NULL); + } + if (mls->disabling_envs == NULL) { + mls->disabling_envs = make_array(cmd->pool, 4, sizeof(env_rec)); + } + envar = push_array(mls->disabling_envs); + envar->name = pstrdup(cmd->pool, &cond[4]); + return NULL; +} + static command_rec config_log_cmds[] = { { "CustomLog", add_custom_log, NULL, RSRC_CONF, TAKE2, "a file name and a custom log format string" }, @@ -670,6 +716,8 @@ "a log format string (see docs)" }, { "CookieLog", set_cookie_log, NULL, RSRC_CONF, TAKE1, "the filename of the cookie log" }, +{ "DoNotLogIf", note_disabling_env, NULL, RSRC_CONF, TAKE1, + "\"env=name\"" }, { NULL } }; @@ -791,5 +839,5 @@ multi_log_transaction, /* logger */ NULL, /* header parser */ NULL, /* child_init */ - NULL /* child_exit */ + NULL /* child_exit */ };