summaryrefslogtreecommitdiffstats
path: root/modules/loggers
diff options
context:
space:
mode:
authorStefan Fritsch <sf@apache.org>2010-11-09 19:59:33 +0100
committerStefan Fritsch <sf@apache.org>2010-11-09 19:59:33 +0100
commit60d6e32249d83c43677caa4746184c4e9728bba5 (patch)
tree42d94ab8e883b95b6e4593b50f4175b23d57f19c /modules/loggers
parentuse temp_pool for some temporary regexps (diff)
downloadapache2-60d6e32249d83c43677caa4746184c4e9728bba5.tar.xz
apache2-60d6e32249d83c43677caa4746184c4e9728bba5.zip
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'" git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1033157 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'modules/loggers')
-rw-r--r--modules/loggers/mod_log_config.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/modules/loggers/mod_log_config.c b/modules/loggers/mod_log_config.c
index 54acb20021..2225aef1e6 100644
--- a/modules/loggers/mod_log_config.c
+++ b/modules/loggers/mod_log_config.c
@@ -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(request_rec *r, config_log_state *cls,
}
}
}
+ 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_parms *cmd, void *dummy, const char *fn,
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]);
}
- if ((envclause[4] == '\0')
- || ((envclause[4] == '!') && (envclause[5] == '\0'))) {
- return "missing environment variable name";
+ 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;
+ }
+ 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,