diff 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
line wrap: on
line diff
--- a/src/core/ngx_times.c
+++ b/src/core/ngx_times.c
@@ -29,6 +29,7 @@ volatile ngx_str_t       ngx_cached_err_
 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_iso8601;
+volatile ngx_str_t       ngx_cached_syslog_time;
 
 #if !(NGX_WIN32)
 
@@ -50,6 +51,8 @@ static u_char            cached_http_log
                                     [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 u_char            cached_syslog_time[NGX_TIME_SLOTS]
+                                    [sizeof("Sep 28 12:00:00")];
 
 
 static char  *week[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
@@ -63,6 +66,7 @@ ngx_time_init(void)
     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_iso8601.len = sizeof("1970-09-28T12:00:00+06:00") - 1;
+    ngx_cached_syslog_time.len = sizeof("Sep 28 12:00:00") - 1;
 
     ngx_cached_time = &cached_time[0];
 
@@ -73,7 +77,7 @@ ngx_time_init(void)
 void
 ngx_time_update(void)
 {
-    u_char          *p0, *p1, *p2, *p3;
+    u_char          *p0, *p1, *p2, *p3, *p4;
     ngx_tm_t         tm, gmt;
     time_t           sec;
     ngx_uint_t       msec;
@@ -166,6 +170,11 @@ ngx_time_update(void)
                        tp->gmtoff < 0 ? '-' : '+',
                        ngx_abs(tp->gmtoff / 60), ngx_abs(tp->gmtoff % 60));
 
+    p4 = &cached_syslog_time[slot][0];
+
+    (void) ngx_sprintf(p4, "%s %2d %02d:%02d:%02d",
+                       months[tm.ngx_tm_mon - 1], tm.ngx_tm_mday,
+                       tm.ngx_tm_hour, tm.ngx_tm_min, tm.ngx_tm_sec);
 
     ngx_memory_barrier();
 
@@ -174,6 +183,7 @@ ngx_time_update(void)
     ngx_cached_err_log_time.data = p1;
     ngx_cached_http_log_time.data = p2;
     ngx_cached_http_log_iso8601.data = p3;
+    ngx_cached_syslog_time.data = p4;
 
     ngx_unlock(&ngx_time_lock);
 }
@@ -184,7 +194,7 @@ ngx_time_update(void)
 void
 ngx_time_sigsafe_update(void)
 {
-    u_char          *p;
+    u_char          *p, *p2;
     ngx_tm_t         tm;
     time_t           sec;
     ngx_time_t      *tp;
@@ -224,9 +234,16 @@ ngx_time_sigsafe_update(void)
                        tm.ngx_tm_mday, tm.ngx_tm_hour,
                        tm.ngx_tm_min, tm.ngx_tm_sec);
 
+    p2 = &cached_syslog_time[slot][0];
+
+    (void) ngx_sprintf(p2, "%s %2d %02d:%02d:%02d",
+                       months[tm.ngx_tm_mon - 1], tm.ngx_tm_mday,
+                       tm.ngx_tm_hour, tm.ngx_tm_min, tm.ngx_tm_sec);
+
     ngx_memory_barrier();
 
     ngx_cached_err_log_time.data = p;
+    ngx_cached_syslog_time.data = p2;
 
     ngx_unlock(&ngx_time_lock);
 }