]> granicus.if.org Git - apache/commitdiff
mod_log_config: instead of using the new dedicated
authorRainer Jung <rjung@apache.org>
Thu, 21 May 2015 15:07:15 +0000 (15:07 +0000)
committerRainer Jung <rjung@apache.org>
Thu, 21 May 2015 15:07:15 +0000 (15:07 +0000)
pattern format "%M" for duration milliseconds,
overload the existing "%D" to choose the time precision
("%{s}D" for seconds, "%{ms}D" for milliseconds and
"%{us}D" for microseconds).

The existing %T and %D without precision are kept for
compatibility.

The previously introduced "%M" (r1677187) is removed,
it has not yet been released. Format pattern characters
are rare, so we should only use a new one if an
existing one isn't a good fit.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1680895 13f79535-47bb-0310-9956-ffa450edef68

docs/manual/mod/mod_log_config.xml
modules/loggers/mod_log_config.c

index e6fd97c66659552069aa977beb60ff05dbf18fa4..3d293036c8924d188f8ce61b7ed24bec95b1fd22 100644 (file)
     <tr><td><code>%D</code></td>
         <td>The time taken to serve the request, in microseconds.</td></tr>
 
+    <tr><td><code>%{<var>UNIT</var>}D</code></td>
+        <td>The time taken to serve the request, in a time unit given by
+        <code>UNIT</code>. Valid units are <code>ms</code> for milliseconds,
+        <code>us</code> for microseconds and <code>s</code> for seconds.
+        Using <code>us</code> gives the same result as <code>%D</code>
+        without any format, using <code>s</code> gives teh same result
+        as <code>%T</code>. Combining <code>%D</code> with a unit is
+        available in 2.4.13 and later.</td></tr>
+        </td></tr>
+
     <tr><td><code>%{<var>VARNAME</var>}e</code></td>
         <td>The contents of the environment variable
         <var>VARNAME</var>.</td></tr>
     <tr><td><code>%m</code></td>
         <td>The request method.</td></tr>
 
-    <tr><td><code>%M</code></td>
-        <td>The time taken to serve the request, in milliseconds.
-        (available in 2.4.13 and later)</td></tr>
-
     <tr><td><code>%{<var>VARNAME</var>}n</code></td>
         <td>The contents of note <var>VARNAME</var> from another
         module.</td></tr>
index 6d93f75dc46d2e295fa18863904339188cbf8671..fd3f5f667012000ba0e5dfebc3ac921a07a0d0d2 100644 (file)
  * %...{format}t:  The time, in the form given by format, which should
  *                 be in strftime(3) format.
  * %...T:  the time taken to serve the request, in seconds.
- * %...M:  the time taken to serve the request, in milliseconds
  * %...D:  the time taken to serve the request, in micro seconds.
+ * %...{s}D:  the time taken to serve the request, in seconds, same as %T.
+ * %...{us}D:  the time taken to serve the request, in micro seconds, same as %D.
+ * %...{ms}D:  the time taken to serve the request, in milliseconds.
  * %...u:  remote user (from auth; may be bogus if return status (%s) is 401)
  * %...U:  the URL path requested.
  * %...v:  the configured name of the server (i.e. which virtual host?)
@@ -803,17 +805,22 @@ static const char *log_request_duration(request_rec *r, char *a)
     return apr_psprintf(r->pool, "%" APR_TIME_T_FMT, apr_time_sec(duration));
 }
 
-static const char *log_request_duration_milliseconds(request_rec *r, char *a)
+static const char *log_request_duration_scaled(request_rec *r, char *a)
 {
     apr_time_t duration = get_request_end_time(r) - r->request_time;
-    return apr_psprintf(r->pool, "%" APR_TIME_T_FMT, apr_time_as_msec(duration));
-}
-
-
-static const char *log_request_duration_microseconds(request_rec *r, char *a)
-{
-    return apr_psprintf(r->pool, "%" APR_TIME_T_FMT,
-                        (get_request_end_time(r) - r->request_time));
+    if (*a == '\0' || !strcasecmp(a, "us")) {
+    }
+    else if (!strcasecmp(a, "ms")) {
+        duration = apr_time_as_msec(duration);
+    }
+    else if (!strcasecmp(a, "s")) {
+        duration = apr_time_sec(duration);
+    }
+    else {
+        /* bogus format */
+        return a;
+    }
+    return apr_psprintf(r->pool, "%" APR_TIME_T_FMT, duration);
 }
 
 /* These next two routines use the canonical name:port so that log
@@ -1844,8 +1851,7 @@ static int log_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
         log_pfn_register(p, "C", log_cookie, 0);
         log_pfn_register(p, "k", log_requests_on_connection, 0);
         log_pfn_register(p, "r", log_request_line, 1);
-        log_pfn_register(p, "D", log_request_duration_microseconds, 1);
-        log_pfn_register(p, "M", log_request_duration_milliseconds, 1);
+        log_pfn_register(p, "D", log_request_duration_scaled, 1);
         log_pfn_register(p, "T", log_request_duration, 1);
         log_pfn_register(p, "U", log_request_uri, 1);
         log_pfn_register(p, "s", log_status, 1);