httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s.@apache.org
Subject svn commit: r1033157 - /httpd/httpd/trunk/modules/loggers/mod_log_config.c
Date Tue, 09 Nov 2010 18:59:33 GMT
Author: sf
Date: Tue Nov  9 18:59:33 2010
New Revision: 1033157

URL: http://svn.apache.org/viewvc?rev=1033157&view=rev
Log:
Add support for conditional logging depending on an expression.
The syntax is a bit unwieldy, the quotes have to start before
the 'expr=':

    CustomLog "logs/cond_log" combined "expr=req('User-Agent') == 'x'"

Modified:
    httpd/httpd/trunk/modules/loggers/mod_log_config.c

Modified: httpd/httpd/trunk/modules/loggers/mod_log_config.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/loggers/mod_log_config.c?rev=1033157&r1=1033156&r2=1033157&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/loggers/mod_log_config.c (original)
+++ httpd/httpd/trunk/modules/loggers/mod_log_config.c Tue Nov  9 18:59:33 2010
@@ -265,6 +265,7 @@ typedef struct {
     apr_array_header_t *format;
     void *log_writer;
     char *condition_var;
+    ap_expr_info_t *condition_expr;
 } config_log_state;
 
 /*
@@ -1081,6 +1082,15 @@ static int config_log_transaction(reques
             }
         }
     }
+    else if (cls->condition_expr != NULL) {
+        const char *err;
+        int rc = ap_expr_exec(r, cls->condition_expr, &err);
+        if (rc < 0) 
+            ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r,
+                           "Error evaluating log condition: %s", err);
+        if (rc <= 0)
+            return DECLINED;
+    }
 
     format = cls->format ? cls->format : default_format;
 
@@ -1229,15 +1239,27 @@ static const char *add_custom_log(cmd_pa
 
     cls = (config_log_state *) apr_array_push(mls->config_logs);
     cls->condition_var = NULL;
+    cls->condition_expr = NULL;
     if (envclause != NULL) {
-        if (strncasecmp(envclause, "env=", 4) != 0) {
-            return "error in condition clause";
+        if (strncasecmp(envclause, "env=", 4) == 0) {
+            if ((envclause[4] == '\0')
+                || ((envclause[4] == '!') && (envclause[5] == '\0'))) {
+                return "missing environment variable name";
+            }
+            cls->condition_var = apr_pstrdup(cmd->pool, &envclause[4]);
+        }
+        else if (strncasecmp(envclause, "expr=", 5) == 0) {
+            const char *err;
+            if ((envclause[5] == '\0'))
+                return "missing condition";
+            cls->condition_expr = ap_expr_parse_cmd(cmd, &envclause[5], &err,
+                                                    NULL);
+            if (err)
+                return err;
         }
-        if ((envclause[4] == '\0')
-            || ((envclause[4] == '!') && (envclause[5] == '\0'))) {
-            return "missing environment variable name";
+        else {
+            return "error in condition clause";
         }
-        cls->condition_var = apr_pstrdup(cmd->pool, &envclause[4]);
     }
 
     cls->fname = fn;
@@ -1277,7 +1299,7 @@ static const command_rec config_log_cmds
 {
 AP_INIT_TAKE23("CustomLog", add_custom_log, NULL, RSRC_CONF,
      "a file name, a custom log format string or format name, "
-     "and an optional \"env=\" clause (see docs)"),
+     "and an optional \"env=\" or \"expr=\" clause (see docs)"),
 AP_INIT_TAKE1("TransferLog", set_transfer_log, NULL, RSRC_CONF,
      "the filename of the access log"),
 AP_INIT_TAKE12("LogFormat", log_format, NULL, RSRC_CONF,



Mime
View raw message