<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>According rfc5424 there could or should be time zone specified in
syslog message. There are problems for example with graylog, so my
patch is adding optional switch to enable different datetime
formatting with timezone support to syslog module.</p>
<p># HG changeset patch<br>
# User Tomas Hulata <a class="moz-txt-link-rfc2396E" href="mailto:tomas.hulata@netbox.cz"><tomas.hulata@netbox.cz></a><br>
# Date 1528838460 -7200<br>
# Tue Jun 12 23:21:00 2018 +0200<br>
# Node ID 309407bf691d77df2d095282b3050c3d9ad3c4ae<br>
# Parent 8e6bb4e6045f7197923717831d2ddf414aa0f443<br>
new option for timezone in syslog message<br>
<br>
diff -r 8e6bb4e6045f -r 309407bf691d src/core/ngx_syslog.c<br>
--- a/src/core/ngx_syslog.c Thu Jun 07 20:04:22 2018 +0300<br>
+++ b/src/core/ngx_syslog.c Tue Jun 12 23:21:00 2018 +0200<br>
@@ -211,6 +211,9 @@<br>
} else if (len == 10 && ngx_strncmp(p,
"nohostname", 10) == 0) {<br>
peer->nohostname = 1;<br>
<br>
+ } else if (len == 2 && ngx_strncmp(p, "tz", 2) ==
0) {<br>
+ peer->tz = 1;<br>
+<br>
} else {<br>
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,<br>
"unknown syslog parameter \"%s\"",
p);<br>
@@ -238,11 +241,13 @@<br>
pri = peer->facility * 8 + peer->severity;<br>
<br>
if (peer->nohostname) {<br>
- return ngx_sprintf(buf, "<%ui>%V %V: ", pri,
&ngx_cached_syslog_time,<br>
+ return ngx_sprintf(buf, "<%ui>%V %V: ", pri,<br>
+ peer->tz ?
&ngx_cached_syslog_time_tz : &ngx_cached_syslog_time,<br>
&peer->tag);<br>
}<br>
<br>
- return ngx_sprintf(buf, "<%ui>%V %V %V: ", pri,
&ngx_cached_syslog_time,<br>
+ return ngx_sprintf(buf, "<%ui>%V %V %V: ", pri,<br>
+ peer->tz ?
&ngx_cached_syslog_time_tz : &ngx_cached_syslog_time,<br>
&ngx_cycle->hostname,
&peer->tag);<br>
}<br>
<br>
diff -r 8e6bb4e6045f -r 309407bf691d src/core/ngx_syslog.h<br>
--- a/src/core/ngx_syslog.h Thu Jun 07 20:04:22 2018 +0300<br>
+++ b/src/core/ngx_syslog.h Tue Jun 12 23:21:00 2018 +0200<br>
@@ -17,6 +17,7 @@<br>
ngx_connection_t conn;<br>
unsigned busy:1;<br>
unsigned nohostname:1;<br>
+ unsigned tz:1;<br>
} ngx_syslog_peer_t;<br>
<br>
<br>
diff -r 8e6bb4e6045f -r 309407bf691d src/core/ngx_times.c<br>
--- a/src/core/ngx_times.c Thu Jun 07 20:04:22 2018 +0300<br>
+++ b/src/core/ngx_times.c Tue Jun 12 23:21:00 2018 +0200<br>
@@ -33,6 +33,7 @@<br>
volatile ngx_str_t ngx_cached_http_log_time;<br>
volatile ngx_str_t ngx_cached_http_log_iso8601;<br>
volatile ngx_str_t ngx_cached_syslog_time;<br>
+volatile ngx_str_t ngx_cached_syslog_time_tz;<br>
<br>
#if !(NGX_WIN32)<br>
<br>
@@ -56,6 +57,9 @@<br>
[sizeof("1970-09-28T12:00:00+06:00")];<br>
static u_char cached_syslog_time[NGX_TIME_SLOTS]<br>
[sizeof("Sep 28 12:00:00")];<br>
+static u_char cached_syslog_time_tz[NGX_TIME_SLOTS]<br>
+
[sizeof("1970-09-28T12:00:00+06:00")];<br>
+<br>
<br>
<br>
static char *week[] = { "Sun", "Mon", "Tue", "Wed", "Thu",
"Fri", "Sat" };<br>
@@ -70,6 +74,7 @@<br>
ngx_cached_http_log_time.len = sizeof("28/Sep/1970:12:00:00
+0600") - 1;<br>
ngx_cached_http_log_iso8601.len =
sizeof("1970-09-28T12:00:00+06:00") - 1;<br>
ngx_cached_syslog_time.len = sizeof("Sep 28 12:00:00") - 1;<br>
+ ngx_cached_syslog_time_tz.len =
sizeof("1970-09-28T12:00:00+06:00") - 1;<br>
<br>
ngx_cached_time = &cached_time[0];<br>
<br>
@@ -80,7 +85,7 @@<br>
void<br>
ngx_time_update(void)<br>
{<br>
- u_char *p0, *p1, *p2, *p3, *p4;<br>
+ u_char *p0, *p1, *p2, *p3, *p4, *p5;<br>
ngx_tm_t tm, gmt;<br>
time_t sec;<br>
ngx_uint_t msec;<br>
@@ -179,6 +184,15 @@<br>
months[tm.ngx_tm_mon - 1], tm.ngx_tm_mday,<br>
tm.ngx_tm_hour, tm.ngx_tm_min,
tm.ngx_tm_sec);<br>
<br>
+ p5 = &cached_syslog_time_tz[slot][0];<br>
+<br>
+ (void) ngx_sprintf(p5,
"%4d-%02d-%02dT%02d:%02d:%02d%c%02i:%02i",<br>
+ tm.ngx_tm_year, tm.ngx_tm_mon,<br>
+ tm.ngx_tm_mday, tm.ngx_tm_hour,<br>
+ tm.ngx_tm_min, tm.ngx_tm_sec,<br>
+ tp->gmtoff < 0 ? '-' : '+',<br>
+ ngx_abs(tp->gmtoff / 60),
ngx_abs(tp->gmtoff % 60));<br>
+<br>
ngx_memory_barrier();<br>
<br>
ngx_cached_time = tp;<br>
@@ -187,6 +201,7 @@<br>
ngx_cached_http_log_time.data = p2;<br>
ngx_cached_http_log_iso8601.data = p3;<br>
ngx_cached_syslog_time.data = p4;<br>
+ ngx_cached_syslog_time_tz.data = p5;<br>
<br>
ngx_unlock(&ngx_time_lock);<br>
}<br>
@@ -222,7 +237,7 @@<br>
void<br>
ngx_time_sigsafe_update(void)<br>
{<br>
- u_char *p, *p2;<br>
+ u_char *p, *p2, *p3;<br>
ngx_tm_t tm;<br>
time_t sec;<br>
ngx_time_t *tp;<br>
@@ -268,10 +283,20 @@<br>
months[tm.ngx_tm_mon - 1], tm.ngx_tm_mday,<br>
tm.ngx_tm_hour, tm.ngx_tm_min,
tm.ngx_tm_sec);<br>
<br>
+ p3 = &cached_syslog_time_tz[slot][0];<br>
+<br>
+ (void) ngx_sprintf(p3,
"%4d-%02d-%02dT%02d:%02d:%02d%c%02i:%02i",<br>
+ tm.ngx_tm_year, tm.ngx_tm_mon,<br>
+ tm.ngx_tm_mday, tm.ngx_tm_hour,<br>
+ tm.ngx_tm_min, tm.ngx_tm_sec,<br>
+ tp->gmtoff < 0 ? '-' : '+',<br>
+ ngx_abs(tp->gmtoff / 60),
ngx_abs(tp->gmtoff % 60));<br>
+<br>
ngx_memory_barrier();<br>
<br>
ngx_cached_err_log_time.data = p;<br>
ngx_cached_syslog_time.data = p2;<br>
+ ngx_cached_syslog_time_tz.data = p3;<br>
<br>
ngx_unlock(&ngx_time_lock);<br>
}<br>
diff -r 8e6bb4e6045f -r 309407bf691d src/core/ngx_times.h<br>
--- a/src/core/ngx_times.h Thu Jun 07 20:04:22 2018 +0300<br>
+++ b/src/core/ngx_times.h Tue Jun 12 23:21:00 2018 +0200<br>
@@ -41,6 +41,7 @@<br>
extern volatile ngx_str_t ngx_cached_http_log_time;<br>
extern volatile ngx_str_t ngx_cached_http_log_iso8601;<br>
extern volatile ngx_str_t ngx_cached_syslog_time;<br>
+extern volatile ngx_str_t ngx_cached_syslog_time_tz;<br>
<br>
/*<br>
* milliseconds elapsed since some unspecified point in the past<br>
<br>
</p>
<div class="moz-signature">-- <br>
S pozdravom<br>
Tomas Hulata<br>
<i style="font-size: 9pt;">vedoucí úseku systemových inženýrů</i><br>
tel: +420 733 163 238<br>
<table style="margin: 0 0 1em 0; border-top: 1px solid #ccc;"
border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="padding: 0.8em 0 0 0;" width="145" valign="top">
<img
src="http://www.netbox.cz/site/images/netbox-logo.gif"
alt="NETBOX" height="31" width="122" align="left"></td>
<td style="padding: 0.8em 0 0 0;" valign="top">
<p style="font-family: Helvetica, Calibri,
Arial,sans-serif; font-size: 11pt; line-height: 1.3em;
margin: 0; padding: 0;">SMART Comp. a.s., Kubíčkova 8,
635 00, Brno <br>
Tel./fax: +420 544 423 411, <a
class="moz-txt-link-abbreviated"
href="http://www.netbox.cz">www.netbox.cz</a></p>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>