You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by jo...@apache.org on 2026/06/02 13:54:18 UTC

svn commit: r1934884 - in httpd/httpd/branches/2.4.x: . changes-entries docs/manual/mod include server

Author: jorton
Date: Tue Jun  2 13:54:17 2026
New Revision: 1934884

Log:
Merge r1931452, r1931453 from trunk:

core: Add millisecond support to ErrorLogFormat time specifiers

%{m} prints the timestamp in millisecond-resolution.

* include/util_time.h:
  Define new AP_CTIME_OPTION_MSEC option for printing time in milliseconds
  format.

* server/util_time.c (ap_recent_ctime_ex):
  Handle AP_CTIME_OPTION_MSEC to print time in a millisecond format.

* server/log.c (log_ctime):
  Recognize the m time option in both fast-path and composite %{...}t formats.

Submitted by: Luboš Uhliarik <luhliari redhat.com>

* server/log.c (log_ctime): Fix syntax error in r1931452
  (added by me when tweaking whitespace, not from the PR author).

Reviewed by: jorton, covener, jim
Github: closes #599

Added:
   httpd/httpd/branches/2.4.x/changes-entries/log-msec.txt   (contents, props changed)
Modified:
   httpd/httpd/branches/2.4.x/   (props changed)
   httpd/httpd/branches/2.4.x/docs/manual/mod/core.xml
   httpd/httpd/branches/2.4.x/include/util_time.h
   httpd/httpd/branches/2.4.x/server/log.c
   httpd/httpd/branches/2.4.x/server/util_time.c

Added: httpd/httpd/branches/2.4.x/changes-entries/log-msec.txt
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ httpd/httpd/branches/2.4.x/changes-entries/log-msec.txt	Tue Jun  2 13:54:17 2026	(r1934884)
@@ -0,0 +1,3 @@
+  *) core: Add support for %{m}t in ErrorLogFormat to log milli-second
+     time resolution (in addition to existing %{u}t for micro-seconds).
+     [Luboš Uhliarik <luhliari redhat.com>]

Modified: httpd/httpd/branches/2.4.x/docs/manual/mod/core.xml
==============================================================================
--- httpd/httpd/branches/2.4.x/docs/manual/mod/core.xml	Tue Jun  2 13:28:23 2026	(r1934883)
+++ httpd/httpd/branches/2.4.x/docs/manual/mod/core.xml	Tue Jun  2 13:54:17 2026	(r1934884)
@@ -1795,6 +1795,9 @@ ErrorLogFormat "[%t] [%l] [pid %P] %F: %
     <tr><td><code>%{u}t</code></td>
         <td>The current time including micro-seconds</td></tr>
 
+    <tr><td><code>%{m}t</code></td>
+        <td>The current time including milliseconds</td></tr>
+
     <tr><td><code>%{cu}t</code></td>
         <td>The current time in ISO 8601 extended format (compact), including
             micro-seconds</td></tr>

Modified: httpd/httpd/branches/2.4.x/include/util_time.h
==============================================================================
--- httpd/httpd/branches/2.4.x/include/util_time.h	Tue Jun  2 13:28:23 2026	(r1934883)
+++ httpd/httpd/branches/2.4.x/include/util_time.h	Tue Jun  2 13:54:17 2026	(r1934884)
@@ -49,6 +49,8 @@ extern "C" {
 #define AP_CTIME_OPTION_COMPACT 0x2
 /* Add timezone offset from GMT ([+-]hhmm) */
 #define AP_CTIME_OPTION_GMTOFF  0x4
+/* Add sub second timestamps with millisecond resolution */
+#define AP_CTIME_OPTION_MSEC    0x8
 
 
 /**

Modified: httpd/httpd/branches/2.4.x/server/log.c
==============================================================================
--- httpd/httpd/branches/2.4.x/server/log.c	Tue Jun  2 13:28:23 2026	(r1934883)
+++ httpd/httpd/branches/2.4.x/server/log.c	Tue Jun  2 13:54:17 2026	(r1934884)
@@ -664,9 +664,15 @@ static int log_ctime(const ap_errorlog_i
         if (arg[0] == 'u' && !arg[1]) { /* no ErrorLogFormat (fast path) */
             option |= AP_CTIME_OPTION_USEC;
         }
-        else if (!ap_strchr_c(arg, '%')) { /* special "%{cuz}t" formats */
+        else if (arg[0] == 'm' && !arg[1]) { /* no ErrorLogFormat (fast path) - msec */
+            option |= AP_CTIME_OPTION_MSEC;
+        }
+        else if (!ap_strchr_c(arg, '%')) { /* special "%{mcuz}t" formats */
             while (*arg) {
                 switch (*arg++) {
+                case 'm':
+                    option |= AP_CTIME_OPTION_MSEC;
+                    break;
                 case 'u':
                     option |= AP_CTIME_OPTION_USEC;
                     break;

Modified: httpd/httpd/branches/2.4.x/server/util_time.c
==============================================================================
--- httpd/httpd/branches/2.4.x/server/util_time.c	Tue Jun  2 13:28:23 2026	(r1934883)
+++ httpd/httpd/branches/2.4.x/server/util_time.c	Tue Jun  2 13:54:17 2026	(r1934884)
@@ -22,6 +22,11 @@
  *   */
 #define AP_CTIME_USEC_LENGTH      7
 
+/* Number of characters needed to format the millisecond part of a timestamp.
+ * Milliseconds have 3 digits plus one separator character makes 4.
+ *   */
+#define AP_CTIME_MSEC_LENGTH      4
+
 /* Length of ISO 8601 date/time (including trailing '\0') */
 #define AP_CTIME_COMPACT_LEN      20
 
@@ -182,6 +187,9 @@ AP_DECLARE(apr_status_t) ap_recent_ctime
     if (option & AP_CTIME_OPTION_USEC) {
         needed += AP_CTIME_USEC_LENGTH;
     }
+    else if (option & AP_CTIME_OPTION_MSEC) {
+        needed += AP_CTIME_MSEC_LENGTH;
+    }
 
     if (option & AP_CTIME_OPTION_GMTOFF) {
         needed += AP_CTIME_GMTOFF_LEN;
@@ -242,11 +250,16 @@ AP_DECLARE(apr_status_t) ap_recent_ctime
     *date_str++ = ':';
     *date_str++ = xt.tm_sec / 10 + '0';
     *date_str++ = xt.tm_sec % 10 + '0';
-    if (option & AP_CTIME_OPTION_USEC) {
+    if (option & (AP_CTIME_OPTION_USEC|AP_CTIME_OPTION_MSEC)) {
         int div;
         int usec = (int)xt.tm_usec;
         *date_str++ = '.';
-        for (div=100000; div>0; div=div/10) {
+        div = 100000;
+        if (!(option & AP_CTIME_OPTION_USEC)) {
+            usec = usec / 1000;
+            div = 100;
+        }
+        for (; div>0; div=div/10) {
             *date_str++ = usec / div + '0';
             usec = usec % div;
         }