mirror of
https://github.com/nginx/nginx.git
synced 2025-06-10 03:22:48 +08:00
$time_iso8601 log variable
patch by Michael Lustfield
This commit is contained in:
parent
0519b43a77
commit
c9d671cd81
@ -27,6 +27,7 @@ volatile ngx_time_t *ngx_cached_time;
|
|||||||
volatile ngx_str_t ngx_cached_err_log_time;
|
volatile ngx_str_t ngx_cached_err_log_time;
|
||||||
volatile ngx_str_t ngx_cached_http_time;
|
volatile ngx_str_t ngx_cached_http_time;
|
||||||
volatile ngx_str_t ngx_cached_http_log_time;
|
volatile ngx_str_t ngx_cached_http_log_time;
|
||||||
|
volatile ngx_str_t ngx_cached_http_log_iso8601;
|
||||||
|
|
||||||
#if !(NGX_WIN32)
|
#if !(NGX_WIN32)
|
||||||
|
|
||||||
@ -46,6 +47,8 @@ static u_char cached_http_time[NGX_TIME_SLOTS]
|
|||||||
[sizeof("Mon, 28 Sep 1970 06:00:00 GMT")];
|
[sizeof("Mon, 28 Sep 1970 06:00:00 GMT")];
|
||||||
static u_char cached_http_log_time[NGX_TIME_SLOTS]
|
static u_char cached_http_log_time[NGX_TIME_SLOTS]
|
||||||
[sizeof("28/Sep/1970:12:00:00 +0600")];
|
[sizeof("28/Sep/1970:12:00:00 +0600")];
|
||||||
|
static u_char cached_http_log_iso8601[NGX_TIME_SLOTS]
|
||||||
|
[sizeof("1970-09-28T12:00:00+06:00")];
|
||||||
|
|
||||||
|
|
||||||
static char *week[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
|
static char *week[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
|
||||||
@ -58,6 +61,7 @@ ngx_time_init(void)
|
|||||||
ngx_cached_err_log_time.len = sizeof("1970/09/28 12:00:00") - 1;
|
ngx_cached_err_log_time.len = sizeof("1970/09/28 12:00:00") - 1;
|
||||||
ngx_cached_http_time.len = sizeof("Mon, 28 Sep 1970 06:00:00 GMT") - 1;
|
ngx_cached_http_time.len = sizeof("Mon, 28 Sep 1970 06:00:00 GMT") - 1;
|
||||||
ngx_cached_http_log_time.len = sizeof("28/Sep/1970:12:00:00 +0600") - 1;
|
ngx_cached_http_log_time.len = sizeof("28/Sep/1970:12:00:00 +0600") - 1;
|
||||||
|
ngx_cached_http_log_iso8601.len = sizeof("1970-09-28T12:00:00+06:00") - 1;
|
||||||
|
|
||||||
ngx_cached_time = &cached_time[0];
|
ngx_cached_time = &cached_time[0];
|
||||||
|
|
||||||
@ -68,7 +72,7 @@ ngx_time_init(void)
|
|||||||
void
|
void
|
||||||
ngx_time_update(void)
|
ngx_time_update(void)
|
||||||
{
|
{
|
||||||
u_char *p0, *p1, *p2;
|
u_char *p0, *p1, *p2, *p3;
|
||||||
ngx_tm_t tm, gmt;
|
ngx_tm_t tm, gmt;
|
||||||
time_t sec;
|
time_t sec;
|
||||||
ngx_uint_t msec;
|
ngx_uint_t msec;
|
||||||
@ -152,6 +156,15 @@ ngx_time_update(void)
|
|||||||
tp->gmtoff < 0 ? '-' : '+',
|
tp->gmtoff < 0 ? '-' : '+',
|
||||||
ngx_abs(tp->gmtoff / 60), ngx_abs(tp->gmtoff % 60));
|
ngx_abs(tp->gmtoff / 60), ngx_abs(tp->gmtoff % 60));
|
||||||
|
|
||||||
|
p3 = &cached_http_log_iso8601[slot][0];
|
||||||
|
|
||||||
|
(void) ngx_sprintf(p3, "%4d-%02d-%02dT%02d:%02d:%02d%c%02d:%02d",
|
||||||
|
tm.ngx_tm_year, tm.ngx_tm_mon,
|
||||||
|
tm.ngx_tm_mday, tm.ngx_tm_hour,
|
||||||
|
tm.ngx_tm_min, tm.ngx_tm_sec,
|
||||||
|
tp->gmtoff < 0 ? '-' : '+',
|
||||||
|
ngx_abs(tp->gmtoff / 60), ngx_abs(tp->gmtoff % 60));
|
||||||
|
|
||||||
|
|
||||||
ngx_memory_barrier();
|
ngx_memory_barrier();
|
||||||
|
|
||||||
@ -159,6 +172,7 @@ ngx_time_update(void)
|
|||||||
ngx_cached_http_time.data = p0;
|
ngx_cached_http_time.data = p0;
|
||||||
ngx_cached_err_log_time.data = p1;
|
ngx_cached_err_log_time.data = p1;
|
||||||
ngx_cached_http_log_time.data = p2;
|
ngx_cached_http_log_time.data = p2;
|
||||||
|
ngx_cached_http_log_iso8601.data = p3;
|
||||||
|
|
||||||
ngx_unlock(&ngx_time_lock);
|
ngx_unlock(&ngx_time_lock);
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,7 @@ extern volatile ngx_time_t *ngx_cached_time;
|
|||||||
extern volatile ngx_str_t ngx_cached_err_log_time;
|
extern volatile ngx_str_t ngx_cached_err_log_time;
|
||||||
extern volatile ngx_str_t ngx_cached_http_time;
|
extern volatile ngx_str_t ngx_cached_http_time;
|
||||||
extern volatile ngx_str_t ngx_cached_http_log_time;
|
extern volatile ngx_str_t ngx_cached_http_log_time;
|
||||||
|
extern volatile ngx_str_t ngx_cached_http_log_iso8601;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* milliseconds elapsed since epoch and truncated to ngx_msec_t,
|
* milliseconds elapsed since epoch and truncated to ngx_msec_t,
|
||||||
|
@ -83,6 +83,8 @@ static u_char *ngx_http_log_pipe(ngx_http_request_t *r, u_char *buf,
|
|||||||
ngx_http_log_op_t *op);
|
ngx_http_log_op_t *op);
|
||||||
static u_char *ngx_http_log_time(ngx_http_request_t *r, u_char *buf,
|
static u_char *ngx_http_log_time(ngx_http_request_t *r, u_char *buf,
|
||||||
ngx_http_log_op_t *op);
|
ngx_http_log_op_t *op);
|
||||||
|
static u_char *ngx_http_log_iso8601(ngx_http_request_t *r, u_char *buf,
|
||||||
|
ngx_http_log_op_t *op);
|
||||||
static u_char *ngx_http_log_msec(ngx_http_request_t *r, u_char *buf,
|
static u_char *ngx_http_log_msec(ngx_http_request_t *r, u_char *buf,
|
||||||
ngx_http_log_op_t *op);
|
ngx_http_log_op_t *op);
|
||||||
static u_char *ngx_http_log_request_time(ngx_http_request_t *r, u_char *buf,
|
static u_char *ngx_http_log_request_time(ngx_http_request_t *r, u_char *buf,
|
||||||
@ -193,6 +195,8 @@ static ngx_http_log_var_t ngx_http_log_vars[] = {
|
|||||||
{ ngx_string("pipe"), 1, ngx_http_log_pipe },
|
{ ngx_string("pipe"), 1, ngx_http_log_pipe },
|
||||||
{ ngx_string("time_local"), sizeof("28/Sep/1970:12:00:00 +0600") - 1,
|
{ ngx_string("time_local"), sizeof("28/Sep/1970:12:00:00 +0600") - 1,
|
||||||
ngx_http_log_time },
|
ngx_http_log_time },
|
||||||
|
{ ngx_string("time_iso8601"), sizeof("1970-09-28T12:00:00+06:00") - 1,
|
||||||
|
ngx_http_log_iso8601 },
|
||||||
{ ngx_string("msec"), NGX_TIME_T_LEN + 4, ngx_http_log_msec },
|
{ ngx_string("msec"), NGX_TIME_T_LEN + 4, ngx_http_log_msec },
|
||||||
{ ngx_string("request_time"), NGX_TIME_T_LEN + 4,
|
{ ngx_string("request_time"), NGX_TIME_T_LEN + 4,
|
||||||
ngx_http_log_request_time },
|
ngx_http_log_request_time },
|
||||||
@ -510,6 +514,12 @@ ngx_http_log_time(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op)
|
|||||||
ngx_cached_http_log_time.len);
|
ngx_cached_http_log_time.len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static u_char *
|
||||||
|
ngx_http_log_iso8601(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op)
|
||||||
|
{
|
||||||
|
return ngx_cpymem(buf, ngx_cached_http_log_iso8601.data,
|
||||||
|
ngx_cached_http_log_iso8601.len);
|
||||||
|
}
|
||||||
|
|
||||||
static u_char *
|
static u_char *
|
||||||
ngx_http_log_msec(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op)
|
ngx_http_log_msec(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op)
|
||||||
|
Loading…
Reference in New Issue
Block a user