Mercurial > hg > nginx
comparison src/core/ngx_times.c @ 5702:777202558122
Added syslog support for error_log and access_log directives.
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Mon, 12 May 2014 16:34:15 +0400 |
parents | e23892a0c917 |
children | 40bea39731d7 |
comparison
equal
deleted
inserted
replaced
5701:1209b8a7b077 | 5702:777202558122 |
---|---|
27 volatile ngx_time_t *ngx_cached_time; | 27 volatile ngx_time_t *ngx_cached_time; |
28 volatile ngx_str_t ngx_cached_err_log_time; | 28 volatile ngx_str_t ngx_cached_err_log_time; |
29 volatile ngx_str_t ngx_cached_http_time; | 29 volatile ngx_str_t ngx_cached_http_time; |
30 volatile ngx_str_t ngx_cached_http_log_time; | 30 volatile ngx_str_t ngx_cached_http_log_time; |
31 volatile ngx_str_t ngx_cached_http_log_iso8601; | 31 volatile ngx_str_t ngx_cached_http_log_iso8601; |
32 volatile ngx_str_t ngx_cached_syslog_time; | |
32 | 33 |
33 #if !(NGX_WIN32) | 34 #if !(NGX_WIN32) |
34 | 35 |
35 /* | 36 /* |
36 * localtime() and localtime_r() are not Async-Signal-Safe functions, therefore, | 37 * localtime() and localtime_r() are not Async-Signal-Safe functions, therefore, |
48 [sizeof("Mon, 28 Sep 1970 06:00:00 GMT")]; | 49 [sizeof("Mon, 28 Sep 1970 06:00:00 GMT")]; |
49 static u_char cached_http_log_time[NGX_TIME_SLOTS] | 50 static u_char cached_http_log_time[NGX_TIME_SLOTS] |
50 [sizeof("28/Sep/1970:12:00:00 +0600")]; | 51 [sizeof("28/Sep/1970:12:00:00 +0600")]; |
51 static u_char cached_http_log_iso8601[NGX_TIME_SLOTS] | 52 static u_char cached_http_log_iso8601[NGX_TIME_SLOTS] |
52 [sizeof("1970-09-28T12:00:00+06:00")]; | 53 [sizeof("1970-09-28T12:00:00+06:00")]; |
54 static u_char cached_syslog_time[NGX_TIME_SLOTS] | |
55 [sizeof("Sep 28 12:00:00")]; | |
53 | 56 |
54 | 57 |
55 static char *week[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; | 58 static char *week[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; |
56 static char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", | 59 static char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
57 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; | 60 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; |
61 { | 64 { |
62 ngx_cached_err_log_time.len = sizeof("1970/09/28 12:00:00") - 1; | 65 ngx_cached_err_log_time.len = sizeof("1970/09/28 12:00:00") - 1; |
63 ngx_cached_http_time.len = sizeof("Mon, 28 Sep 1970 06:00:00 GMT") - 1; | 66 ngx_cached_http_time.len = sizeof("Mon, 28 Sep 1970 06:00:00 GMT") - 1; |
64 ngx_cached_http_log_time.len = sizeof("28/Sep/1970:12:00:00 +0600") - 1; | 67 ngx_cached_http_log_time.len = sizeof("28/Sep/1970:12:00:00 +0600") - 1; |
65 ngx_cached_http_log_iso8601.len = sizeof("1970-09-28T12:00:00+06:00") - 1; | 68 ngx_cached_http_log_iso8601.len = sizeof("1970-09-28T12:00:00+06:00") - 1; |
69 ngx_cached_syslog_time.len = sizeof("Sep 28 12:00:00") - 1; | |
66 | 70 |
67 ngx_cached_time = &cached_time[0]; | 71 ngx_cached_time = &cached_time[0]; |
68 | 72 |
69 ngx_time_update(); | 73 ngx_time_update(); |
70 } | 74 } |
71 | 75 |
72 | 76 |
73 void | 77 void |
74 ngx_time_update(void) | 78 ngx_time_update(void) |
75 { | 79 { |
76 u_char *p0, *p1, *p2, *p3; | 80 u_char *p0, *p1, *p2, *p3, *p4; |
77 ngx_tm_t tm, gmt; | 81 ngx_tm_t tm, gmt; |
78 time_t sec; | 82 time_t sec; |
79 ngx_uint_t msec; | 83 ngx_uint_t msec; |
80 ngx_time_t *tp; | 84 ngx_time_t *tp; |
81 struct timeval tv; | 85 struct timeval tv; |
164 tm.ngx_tm_mday, tm.ngx_tm_hour, | 168 tm.ngx_tm_mday, tm.ngx_tm_hour, |
165 tm.ngx_tm_min, tm.ngx_tm_sec, | 169 tm.ngx_tm_min, tm.ngx_tm_sec, |
166 tp->gmtoff < 0 ? '-' : '+', | 170 tp->gmtoff < 0 ? '-' : '+', |
167 ngx_abs(tp->gmtoff / 60), ngx_abs(tp->gmtoff % 60)); | 171 ngx_abs(tp->gmtoff / 60), ngx_abs(tp->gmtoff % 60)); |
168 | 172 |
173 p4 = &cached_syslog_time[slot][0]; | |
174 | |
175 (void) ngx_sprintf(p4, "%s %2d %02d:%02d:%02d", | |
176 months[tm.ngx_tm_mon - 1], tm.ngx_tm_mday, | |
177 tm.ngx_tm_hour, tm.ngx_tm_min, tm.ngx_tm_sec); | |
169 | 178 |
170 ngx_memory_barrier(); | 179 ngx_memory_barrier(); |
171 | 180 |
172 ngx_cached_time = tp; | 181 ngx_cached_time = tp; |
173 ngx_cached_http_time.data = p0; | 182 ngx_cached_http_time.data = p0; |
174 ngx_cached_err_log_time.data = p1; | 183 ngx_cached_err_log_time.data = p1; |
175 ngx_cached_http_log_time.data = p2; | 184 ngx_cached_http_log_time.data = p2; |
176 ngx_cached_http_log_iso8601.data = p3; | 185 ngx_cached_http_log_iso8601.data = p3; |
186 ngx_cached_syslog_time.data = p4; | |
177 | 187 |
178 ngx_unlock(&ngx_time_lock); | 188 ngx_unlock(&ngx_time_lock); |
179 } | 189 } |
180 | 190 |
181 | 191 |
182 #if !(NGX_WIN32) | 192 #if !(NGX_WIN32) |
183 | 193 |
184 void | 194 void |
185 ngx_time_sigsafe_update(void) | 195 ngx_time_sigsafe_update(void) |
186 { | 196 { |
187 u_char *p; | 197 u_char *p, *p2; |
188 ngx_tm_t tm; | 198 ngx_tm_t tm; |
189 time_t sec; | 199 time_t sec; |
190 ngx_time_t *tp; | 200 ngx_time_t *tp; |
191 struct timeval tv; | 201 struct timeval tv; |
192 | 202 |
222 (void) ngx_sprintf(p, "%4d/%02d/%02d %02d:%02d:%02d", | 232 (void) ngx_sprintf(p, "%4d/%02d/%02d %02d:%02d:%02d", |
223 tm.ngx_tm_year, tm.ngx_tm_mon, | 233 tm.ngx_tm_year, tm.ngx_tm_mon, |
224 tm.ngx_tm_mday, tm.ngx_tm_hour, | 234 tm.ngx_tm_mday, tm.ngx_tm_hour, |
225 tm.ngx_tm_min, tm.ngx_tm_sec); | 235 tm.ngx_tm_min, tm.ngx_tm_sec); |
226 | 236 |
237 p2 = &cached_syslog_time[slot][0]; | |
238 | |
239 (void) ngx_sprintf(p2, "%s %2d %02d:%02d:%02d", | |
240 months[tm.ngx_tm_mon - 1], tm.ngx_tm_mday, | |
241 tm.ngx_tm_hour, tm.ngx_tm_min, tm.ngx_tm_sec); | |
242 | |
227 ngx_memory_barrier(); | 243 ngx_memory_barrier(); |
228 | 244 |
229 ngx_cached_err_log_time.data = p; | 245 ngx_cached_err_log_time.data = p; |
246 ngx_cached_syslog_time.data = p2; | |
230 | 247 |
231 ngx_unlock(&ngx_time_lock); | 248 ngx_unlock(&ngx_time_lock); |
232 } | 249 } |
233 | 250 |
234 #endif | 251 #endif |