Skip to content

Commit d565275

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 6ab1946 commit d565275

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
@@ -1761,6 +1761,9 @@ ErrorLogFormat "[%t] [%l] [pid %P] %F: %E: [client %a] %M"
17611761
<tr><td><code>%{u}t</code></td>
17621762
<td>The current time including micro-seconds</td></tr>
17631763

1764+
<tr><td><code>%{m}t</code></td>
1765+
<td>The current time including milliseconds</td></tr>
1766+
17641767
<tr><td><code>%{cu}t</code></td>
17651768
<td>The current time in ISO 8601 extended format (compact), including
17661769
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
@@ -585,9 +585,15 @@ static int log_ctime(const ap_errorlog_info *info, const char *arg,
585585
if (arg[0] == 'u' && !arg[1]) { /* no ErrorLogFormat (fast path) */
586586
option |= AP_CTIME_OPTION_USEC;
587587
}
588-
else if (!ap_strchr_c(arg, '%')) { /* special "%{cuz}t" formats */
588+
else if (arg[0] == 'm' && !arg[1]) /* no ErrorLogFormat (fast path) - msec */
589+
option |= AP_CTIME_OPTION_MSEC;
590+
}
591+
else if (!ap_strchr_c(arg, '%')) { /* special "%{mcuz}t" formats */
589592
while (*arg) {
590593
switch (*arg++) {
594+
case 'm':
595+
option |= AP_CTIME_OPTION_MSEC;
596+
break;
591597
case 'u':
592598
option |= AP_CTIME_OPTION_USEC;
593599
break;

server/util_time.c

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

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

@@ -184,6 +189,9 @@ AP_DECLARE(apr_status_t) ap_recent_ctime_ex(char *date_str, apr_time_t t,
184189
if (option & AP_CTIME_OPTION_USEC) {
185190
needed += AP_CTIME_USEC_LENGTH;
186191
}
192+
else if (option & AP_CTIME_OPTION_MSEC) {
193+
needed += AP_CTIME_MSEC_LENGTH;
194+
}
187195

188196
if (option & AP_CTIME_OPTION_GMTOFF) {
189197
needed += AP_CTIME_GMTOFF_LEN;
@@ -244,11 +252,16 @@ AP_DECLARE(apr_status_t) ap_recent_ctime_ex(char *date_str, apr_time_t t,
244252
*date_str++ = ':';
245253
*date_str++ = xt.tm_sec / 10 + '0';
246254
*date_str++ = xt.tm_sec % 10 + '0';
247-
if (option & AP_CTIME_OPTION_USEC) {
255+
if (option & (AP_CTIME_OPTION_USEC|AP_CTIME_OPTION_MSEC)) {
248256
int div;
249257
int usec = (int)xt.tm_usec;
250258
*date_str++ = '.';
251-
for (div=100000; div>0; div=div/10) {
259+
div = 100000;
260+
if (!(option & AP_CTIME_OPTION_USEC)) {
261+
usec = usec / 1000;
262+
div = 100;
263+
}
264+
for (; div>0; div=div/10) {
252265
*date_str++ = usec / div + '0';
253266
usec = usec % div;
254267
}

0 commit comments

Comments
 (0)