httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ruediger Pluem <rpl...@apache.org>
Subject Re: svn commit: r992806 - in /httpd/httpd/trunk: ./ docs/manual/ docs/manual/mod/ include/ modules/loggers/ server/
Date Mon, 06 Sep 2010 07:30:26 GMT


On 09/05/2010 05:44 PM, sf@apache.org wrote:
> Author: sf
> Date: Sun Sep  5 15:44:19 2010
> New Revision: 992806
> 
> URL: http://svn.apache.org/viewvc?rev=992806&view=rev
> Log:
> Add ErrorLogFormat directive for configuring the error log format, including
> additional information that is logged once per connection or request.
> 
> Add error log IDs for connections and request to allow correlating error log
> lines and the corresponding access log entry.
> 
> Modified:
>     httpd/httpd/trunk/CHANGES
>     httpd/httpd/trunk/STATUS
>     httpd/httpd/trunk/docs/manual/logs.xml
>     httpd/httpd/trunk/docs/manual/mod/core.xml
>     httpd/httpd/trunk/docs/manual/mod/mod_log_config.xml
>     httpd/httpd/trunk/include/ap_mmn.h
>     httpd/httpd/trunk/include/http_config.h
>     httpd/httpd/trunk/include/http_core.h
>     httpd/httpd/trunk/include/httpd.h
>     httpd/httpd/trunk/include/util_time.h
>     httpd/httpd/trunk/modules/loggers/mod_log_config.c
>     httpd/httpd/trunk/server/config.c
>     httpd/httpd/trunk/server/core.c
>     httpd/httpd/trunk/server/log.c
>     httpd/httpd/trunk/server/util_time.c
> 

> 
> Modified: httpd/httpd/trunk/server/core.c
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/core.c?rev=992806&r1=992805&r2=992806&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/server/core.c (original)
> +++ httpd/httpd/trunk/server/core.c Sun Sep  5 15:44:19 2010

> +static apr_array_header_t *parse_errorlog_string(apr_pool_t *p,
> +                                                 const char *s,
> +                                                 const char **err,
> +                                                 int want_msg_fmt)
> +{
> +    apr_array_header_t *a = apr_array_make(p, 30,
> +                                           sizeof(ap_errorlog_format_item));
> +    char *res;
> +    int seen_msg_fmt = 0;
> +
> +    while (s && *s) {
> +        ap_errorlog_format_item *item =
> +            (ap_errorlog_format_item *)apr_array_push(a);
> +        memset(item, 0, sizeof(*item));
> +        res = parse_errorlog_item(p, item, &s);
> +        if (res) {
> +            *err = res;
> +            return NULL;
> +        }
> +        if (item->flags & AP_ERRORLOG_FLAG_MESSAGE) {
> +            if (!want_msg_fmt) {
> +                *err = "%M cannot be used in once-per-request or "
> +                       "once-per-connection formats";
> +                return NULL;
> +            }
> +            seen_msg_fmt = 1;
> +        }
> +    }
> +
> +    if (want_msg_fmt && !seen_msg_fmt) {
> +        *err = "main ErrorLogFormat must contain message format string '%M'";
> +        return NULL;
> +    }
> +
> +    return a;
> +}
> +
> +static const char *set_errorlog_format(cmd_parms *cmd, void *dummy,
> +                                       const char *arg1, const char *arg2)
> +{
> +    const char *err_string = NULL;
> +    core_server_config *conf = ap_get_module_config(cmd->server->module_config,
> +                                                    &core_module);
> +
> +    if (!arg2) {
> +        conf->error_log_format = parse_errorlog_string(cmd->pool, arg1,
> +                                                       &err_string, 1);
> +    }
> +    else if (!strcasecmp(arg1, "connection")) {
> +        if (!conf->error_log_conn) {
> +            conf->error_log_conn = apr_array_make(cmd->pool, 5,
> +                                                  sizeof(apr_array_header_t *));
> +        }
> +
> +        if (arg2 && *arg2) {


arg2 is always != NULL.

> +            apr_array_header_t **e;
> +            e = (apr_array_header_t **) apr_array_push(conf->error_log_conn);
> +            *e = parse_errorlog_string(cmd->pool, arg2, &err_string, 0);
> +        }
> +    }
> +    else if (!strcasecmp(arg1, "request")) {
> +        if (!conf->error_log_req) {
> +            conf->error_log_req = apr_array_make(cmd->pool, 5,
> +                                                 sizeof(apr_array_header_t *));
> +        }
> +
> +        if (arg2 && *arg2) {


arg2 is always != NULL.


> +            apr_array_header_t **e;
> +            e = (apr_array_header_t **) apr_array_push(conf->error_log_req);
> +            *e = parse_errorlog_string(cmd->pool, arg2, &err_string, 0);
> +        }
> +    }
> +    else {
> +        err_string = "ErrorLogFormat type must be one of request, connection";
> +    }
> +
> +    return err_string;
> +}
> +
> +AP_DECLARE(void) ap_register_errorlog_handler(apr_pool_t *p, char *tag,
> +                                              ap_errorlog_handler_fn_t *handler,
> +                                              int flags)
> +{
> +    ap_errorlog_handler *log_struct = apr_palloc(p, sizeof(*log_struct));
> +    log_struct->func = handler;
> +    log_struct->flags = flags;
> +
> +    apr_hash_set(errorlog_hash, tag, 1, (const void *)log_struct);
> +}
> +
> +
>  /* Note --- ErrorDocument will now work from .htaccess files.
>   * The AllowOverride of Fileinfo allows webmasters to turn it off
>   */



> Modified: httpd/httpd/trunk/server/log.c
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/log.c?rev=992806&r1=992805&r2=992806&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/server/log.c (original)
> +++ httpd/httpd/trunk/server/log.c Sun Sep  5 15:44:19 2010

> @@ -677,75 +704,303 @@ static void log_error_core(const char *f
>              file = p + 1;
>          }
>  #endif /*_OSD_POSIX || WIN32 */
> -        len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
> -                            "%s(%d): ", file, line);
> +        return apr_snprintf(buf, buflen, "%s(%d)", file, info->line);
> +    }
> +}
> +
> +static int log_apr_status(const ap_errorlog_info *info, const char *arg,
> +                          char *buf, int buflen)
> +{
> +    apr_status_t status = info->status;
> +    int len = 0;
> +    if (!status)
> +        return 0;
> +
> +    if (status < APR_OS_START_EAIERR) {
> +        len += apr_snprintf(buf + len, buflen - len,


len is always 0. Why this + and -?

> +                            "(%d)", status);
> +    }
> +    else if (status < APR_OS_START_SYSERR) {
> +        len += apr_snprintf(buf + len, buflen - len,
> +                            "(EAI %d)", status - APR_OS_START_EAIERR);

len is always 0. Why this + and -?

> +    }
> +    else if (status < 100000 + APR_OS_START_SYSERR) {
> +        len += apr_snprintf(buf + len, buflen - len,
> +                            "(OS %d)", status - APR_OS_START_SYSERR);


len is always 0. Why this + and -?

>      }
> +    else {
> +        len += apr_snprintf(buf + len, buflen - len,
> +                            "(os 0x%08x)", status - APR_OS_START_SYSERR);
> +    }
> +    apr_strerror(status, buf + len, buflen - len);
> +    len += strlen(buf + len);
> +    return len;
> +}
> +
> +static int log_header(const ap_errorlog_info *info, const char *arg,
> +                      char *buf, int buflen)
> +{

> +
> +    /*
> +     * The apr-util docs wrongly states encoded strings are not 0-terminated.
> +     * Let's be save and allocate an additional byte.
> +     */
> +    len = 1 + apr_base64_encode_len(sizeof(id));
> +    encoded = apr_palloc(r ? r->pool : c->pool, len);
> +    apr_base64_encode(encoded, (char *)&id, sizeof(id));
> +    encoded[11] = '\0'; /* omit last char which is always '=' */

Why 11 and not len?

> +
> +    /* need to cast const away */
> +    if (r) {
> +        ((request_rec *)r)->log_id = encoded;
> +    }
> +    else {
> +        ((conn_rec *)c)->log_id = encoded;
> +    }
> +}
> +
> +/*
> + * This is used if no error log format is defined and during startup.
> + * It automatically omits the timestamp if logging to syslog.
> + */
> +static int do_errorlog_default(const ap_errorlog_info *info, char *buf,
> +                               int buflen, int *errstr_start, int *errstr_end,
> +                               const char *errstr_fmt, va_list args)

Regards

RĂ¼diger

Mime
View raw message