Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/manual/mod/core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1761,6 +1761,9 @@ ErrorLogFormat "[%t] [%l] [pid %P] %F: %E: [client %a] %M"
<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>
Expand Down
2 changes: 2 additions & 0 deletions include/util_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -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


/**
Expand Down
8 changes: 6 additions & 2 deletions server/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,10 +584,14 @@ static int log_ctime(const ap_errorlog_info *info, const char *arg,
if (arg) {
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;
Expand Down
16 changes: 14 additions & 2 deletions server/util_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,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

Expand Down Expand Up @@ -183,6 +188,8 @@ AP_DECLARE(apr_status_t) ap_recent_ctime_ex(char *date_str, apr_time_t t,

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) {
Expand Down Expand Up @@ -244,11 +251,16 @@ AP_DECLARE(apr_status_t) ap_recent_ctime_ex(char *date_str, apr_time_t t,
*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;
}
Expand Down