From: Stefan Fritsch Date: Sun, 12 Sep 2010 12:59:10 +0000 (+0000) Subject: add errorlog formats for request notes and env vars X-Git-Tag: 2.3.9~502 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d0bc2d2cfb3d6352cd45b4f6935c709fbddc466b;p=apache add errorlog formats for request notes and env vars git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@996307 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/docs/manual/mod/core.xml b/docs/manual/mod/core.xml index 6aa6333c2e..caeecc8874 100644 --- a/docs/manual/mod/core.xml +++ b/docs/manual/mod/core.xml @@ -1106,6 +1106,9 @@ in case of an error %...A Local IP-address and port + %...{name}e + Request environment variable name + %...E APR/OS error status code and string @@ -1136,6 +1139,9 @@ in case of an error %M The actual log message + %...{name}n + Request note name + %...P Process ID of current process diff --git a/server/log.c b/server/log.c index 80b28443fd..72ff781d51 100644 --- a/server/log.c +++ b/server/log.c @@ -736,38 +736,57 @@ static int log_apr_status(const ap_errorlog_info *info, const char *arg, return len; } -static int log_header(const ap_errorlog_info *info, const char *arg, - char *buf, int buflen) +static int log_table_entry(const apr_table_t *table, const char *name, + char *buf, int buflen) { - const char *header; - int len = 0; #ifndef AP_UNSAFE_ERROR_LOG_UNESCAPED + const char *value; char scratch[MAX_STRING_LEN]; -#endif - if ( info->r && (header = apr_table_get(info->r->headers_in, arg)) -#ifndef AP_UNSAFE_ERROR_LOG_UNESCAPED - && ap_escape_errorlog_item(scratch, header, MAX_STRING_LEN) -#endif - ) { - len = cpystrn(buf, -#ifndef AP_UNSAFE_ERROR_LOG_UNESCAPED - scratch, + if ((value = apr_table_get(table, name)) != NULL) { + ap_escape_errorlog_item(scratch, value, MAX_STRING_LEN); + return cpystrn(buf, scratch, buflen); + } + + return 0; #else - header, + return cpystrn(buf, apr_table_get(table, name), buflen); #endif - buflen); - } - return len; } +static int log_header(const ap_errorlog_info *info, const char *arg, + char *buf, int buflen) +{ + if (info->r) + return log_table_entry(info->r->headers_in, arg, buf, buflen); + + return 0; +} + +static int log_note(const ap_errorlog_info *info, const char *arg, + char *buf, int buflen) +{ + /* XXX: maybe escaping the entry is not necessary for notes? */ + if (info->r) + return log_table_entry(info->r->notes, arg, buf, buflen); + return 0; +} +static int log_env_var(const ap_errorlog_info *info, const char *arg, + char *buf, int buflen) +{ + if (info->r) + return log_table_entry(info->r->subprocess_env, arg, buf, buflen); + + return 0; +} AP_DECLARE(void) ap_register_builtin_errorlog_handlers(apr_pool_t *p) { ap_register_errorlog_handler(p, "a", log_remote_address, 0); ap_register_errorlog_handler(p, "A", log_local_address, 0); + ap_register_errorlog_handler(p, "e", log_env_var, 0); ap_register_errorlog_handler(p, "E", log_apr_status, 0); ap_register_errorlog_handler(p, "F", log_file_line, 0); ap_register_errorlog_handler(p, "i", log_header, 0); @@ -775,11 +794,10 @@ AP_DECLARE(void) ap_register_builtin_errorlog_handlers(apr_pool_t *p) ap_register_errorlog_handler(p, "l", log_loglevel, 0); ap_register_errorlog_handler(p, "L", log_log_id, 0); ap_register_errorlog_handler(p, "m", log_module_name, 0); + ap_register_errorlog_handler(p, "n", log_note, 0); ap_register_errorlog_handler(p, "P", log_pid, 0); ap_register_errorlog_handler(p, "t", log_ctime, 0); ap_register_errorlog_handler(p, "T", log_tid, 0); - - /* XXX: TODO: envvars, notes */ } static void add_log_id(const conn_rec *c, const request_rec *r)