Skip to content

Commit 4a60295

Browse files
committed
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> Github: closes #597 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1931452 13f79535-47bb-0310-9956-ffa450edef68
1 parent 98f3dad commit 4a60295

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

changes-entries/log-msec.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*) core: Add support for %{m}t in ErrorLogFormat to log milli-second
2+
time resolution (in addition to existing %{u}t for micro-seconds).
3+
[Luboš Uhliarik <luhliari redhat.com>]

docs/manual/mod/core.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,6 +1736,9 @@ ErrorLogFormat "[%t] [%l] [pid %P] %F: %E: [client %a] %M"
17361736
<tr><td><code>%{u}t</code></td>
17371737
<td>The current time including micro-seconds</td></tr>
17381738

1739+
<tr><td><code>%{m}t</code></td>
1740+
<td>The current time including milliseconds</td></tr>
1741+
17391742
<tr><td><code>%{cu}t</code></td>
17401743
<td>The current time in ISO 8601 extended format (compact), including
17411744
micro-seconds</td></tr>

include/util_time.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ extern "C" {
4949
#define AP_CTIME_OPTION_COMPACT 0x2
5050
/* Add timezone offset from GMT ([+-]hhmm) */
5151
#define AP_CTIME_OPTION_GMTOFF 0x4
52+
/* Add sub second timestamps with millisecond resolution */
53+
#define AP_CTIME_OPTION_MSEC 0x8
5254

5355

5456
/**

server/log.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,9 +664,15 @@ static int log_ctime(const ap_errorlog_info *info, const char *arg,
664664
if (arg[0] == 'u' && !arg[1]) { /* no ErrorLogFormat (fast path) */
665665
option |= AP_CTIME_OPTION_USEC;
666666
}
667-
else if (!ap_strchr_c(arg, '%')) { /* special "%{cuz}t" formats */
667+
else if (arg[0] == 'm' && !arg[1]) /* no ErrorLogFormat (fast path) - msec */
668+
option |= AP_CTIME_OPTION_MSEC;
669+
}
670+
else if (!ap_strchr_c(arg, '%')) { /* special "%{mcuz}t" formats */
668671
while (*arg) {
669672
switch (*arg++) {
673+
case 'm':
674+
option |= AP_CTIME_OPTION_MSEC;
675+
break;
670676
case 'u':
671677
option |= AP_CTIME_OPTION_USEC;
672678
break;

server/util_time.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
* */
2323
#define AP_CTIME_USEC_LENGTH 7
2424

25+
/* Number of characters needed to format the millisecond part of a timestamp.
26+
* Milliseconds have 3 digits plus one separator character makes 4.
27+
* */
28+
#define AP_CTIME_MSEC_LENGTH 4
29+
2530
/* Length of ISO 8601 date/time (including trailing '\0') */
2631
#define AP_CTIME_COMPACT_LEN 20
2732

@@ -182,6 +187,9 @@ AP_DECLARE(apr_status_t) ap_recent_ctime_ex(char *date_str, apr_time_t t,
182187
if (option & AP_CTIME_OPTION_USEC) {
183188
needed += AP_CTIME_USEC_LENGTH;
184189
}
190+
else if (option & AP_CTIME_OPTION_MSEC) {
191+
needed += AP_CTIME_MSEC_LENGTH;
192+
}
185193

186194
if (option & AP_CTIME_OPTION_GMTOFF) {
187195
needed += AP_CTIME_GMTOFF_LEN;
@@ -242,11 +250,16 @@ AP_DECLARE(apr_status_t) ap_recent_ctime_ex(char *date_str, apr_time_t t,
242250
*date_str++ = ':';
243251
*date_str++ = xt.tm_sec / 10 + '0';
244252
*date_str++ = xt.tm_sec % 10 + '0';
245-
if (option & AP_CTIME_OPTION_USEC) {
253+
if (option & (AP_CTIME_OPTION_USEC|AP_CTIME_OPTION_MSEC)) {
246254
int div;
247255
int usec = (int)xt.tm_usec;
248256
*date_str++ = '.';
249-
for (div=100000; div>0; div=div/10) {
257+
div = 100000;
258+
if (!(option & AP_CTIME_OPTION_USEC)) {
259+
usec = usec / 1000;
260+
div = 100;
261+
}
262+
for (; div>0; div=div/10) {
250263
*date_str++ = usec / div + '0';
251264
usec = usec % div;
252265
}

0 commit comments

Comments
 (0)