[syslog-ng]TimeZone Macros Patch

Robin * Slomkowski pretender@parts-unknown.com
Thu, 12 Sep 2002 21:00:11 -0700


--IS0zKkzwUGydFO0o
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

I have created a patch based on 
syslog-ng-1.5.20

That adds two new macros.

TZOFFSET	The time-zone as hour offset from GMT. e.g. '-0700'
TZ      	The time zone or name or abbreviation. e.g. 'PDT'

usable like all other macros. $TZ and $TZOFFSET

the affected source files are 

doc/sgml/syslog-ng.sgml		documentation update
src/affile.c			The code change

you also need to 
/bin/touch src/affile.c.x

to get it to build correctly after you have applied the patch.
and you need to explicitly rebuild the documentation if you want the
documentation updates.

I have the need for this as I have to coordinate syslog files with other
application log files that are in multiple data centers.  And since a
standard syslog entry does not contain the timezone, I need the log file
name to contain the GMT offset so I can correlate the data in a useful
manner with the logs in other timezones, and daylight saving times.

Hope this patch meets the code standards for this project and that
others may find it useful.

-- 
-R*S
                                   San Francisco, CA
Robin * Slomkowski                 pretender@rslomkow.org

--IS0zKkzwUGydFO0o
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="TZ-macro.patch"

diff -r -u syslog-ng-1.5.20/doc/sgml/syslog-ng.sgml syslog-ng-1.5.20-new/doc/sgml/syslog-ng.sgml
--- syslog-ng-1.5.20/doc/sgml/syslog-ng.sgml	2002-04-26 02:47:25.000000000 -0700
+++ syslog-ng-1.5.20-new/doc/sgml/syslog-ng.sgml	2002-09-12 20:17:02.000000000 -0700
@@ -909,6 +909,18 @@
 		</entry>
 	      </row>
 	      <row>
+		<entry>TZOFFSET</entry>
+		<entry>
+		  The time-zone as hour offset from GMT. e.g. '-0700'
+		<entry>
+	      </row>
+	      <row>
+		<entry>TZ</entry>
+		<entry>
+		  The time zone or name or abbreviation. e.g. 'PDT'
+		</entry>
+	      </row>
+	      <row>
 		<entry>FULLHOST</entry> 
 		<entry>
 		</entry>
diff -r -u syslog-ng-1.5.20/src/affile.c syslog-ng-1.5.20-new/src/affile.c
--- syslog-ng-1.5.20/src/affile.c	2002-08-21 07:03:50.000000000 -0700
+++ syslog-ng-1.5.20-new/src/affile.c	2002-09-12 20:16:19.000000000 -0700
@@ -507,41 +507,47 @@
 #define M_MIN      10
 #define M_SEC      11
 #define M_WEEKDAY  12
-#define M_UNIXTIME 13
+#define M_TZOFFSET 13
+#define M_TZ       14
+#define M_UNIXTIME 15
+
+#define M_DATE_RECVD     16
+#define M_FULLDATE_RECVD 17
+#define M_ISODATE_RECVD  18
+#define M_YEAR_RECVD     19
+#define M_MONTH_RECVD    20
+#define M_DAY_RECVD      21
+#define M_HOUR_RECVD     22
+#define M_MIN_RECVD      23
+#define M_SEC_RECVD      24
+#define M_WEEKDAY_RECVD  25
+#define M_TZOFFSET_RECVD 26
+#define M_TZ_RECVD       27
+#define M_UNIXTIME_RECVD 28
+
+#define M_DATE_STAMP     30
+#define M_FULLDATE_STAMP 31
+#define M_ISODATE_STAMP  32
+#define M_YEAR_STAMP     33
+#define M_MONTH_STAMP    34
+#define M_DAY_STAMP      35
+#define M_HOUR_STAMP     36
+#define M_MIN_STAMP      37
+#define M_SEC_STAMP      38
+#define M_WEEKDAY_STAMP  39
+#define M_TZOFFSET_STAMP 40
+#define M_TZ_STAMP       41
+#define M_UNIXTIME_STAMP 42
+
+#define M_FULLHOST       43
+#define M_HOST           44
+#define M_FULLHOST_FROM  45
+#define M_HOST_FROM      46
+#define M_PROGRAM        47
 
-#define M_DATE_RECVD     14
-#define M_FULLDATE_RECVD 15
-#define M_ISODATE_RECVD  16
-#define M_YEAR_RECVD     17
-#define M_MONTH_RECVD    18
-#define M_DAY_RECVD      19
-#define M_HOUR_RECVD     20
-#define M_MIN_RECVD      21
-#define M_SEC_RECVD      22
-#define M_WEEKDAY_RECVD  23
-#define M_UNIXTIME_RECVD 24
-
-#define M_DATE_STAMP     25
-#define M_FULLDATE_STAMP 26
-#define M_ISODATE_STAMP  27
-#define M_YEAR_STAMP     28
-#define M_MONTH_STAMP    29
-#define M_DAY_STAMP      30
-#define M_HOUR_STAMP     31
-#define M_MIN_STAMP      32
-#define M_SEC_STAMP      33
-#define M_WEEKDAY_STAMP  34
-#define M_UNIXTIME_STAMP 35
-
-#define M_FULLHOST 36
-#define M_HOST     37
-#define M_FULLHOST_FROM 38
-#define M_HOST_FROM  39
-#define M_PROGRAM  40
+#define M_MESSAGE        48
 
-#define M_MESSAGE  41
-
-#define M_SOURCE_IP 42
+#define M_SOURCE_IP      49
 
 int append_string(char **dest, int *left, char *str, int length, int escape)
 {
@@ -666,6 +672,8 @@
 	case M_HOUR_RECVD:
 	case M_MIN_RECVD:
 	case M_SEC_RECVD:
+	case M_TZOFFSET_RECVD:
+	case M_TZ_RECVD:
 	case M_UNIXTIME_RECVD:
 
 	case M_FULLDATE_STAMP:
@@ -678,6 +686,8 @@
 	case M_HOUR_STAMP:
 	case M_MIN_STAMP:
 	case M_SEC_STAMP:
+	case M_TZOFFSET_STAMP:
+	case M_TZ_STAMP:
 	case M_UNIXTIME_STAMP:
 
 	case M_FULLDATE:
@@ -690,6 +700,8 @@
 	case M_HOUR:
 	case M_MIN:
 	case M_SEC:
+	case M_TZOFFSET:
+	case M_TZ:
 	case M_UNIXTIME: {
 		/* year, month, day */
 		struct tm *tm;
@@ -706,6 +718,8 @@
 	       	case M_HOUR_RECVD:    
 	       	case M_MIN_RECVD:     
 	       	case M_SEC_RECVD:     
+		case M_TZOFFSET_RECVD:
+		case M_TZ_RECVD:
 	       	case M_UNIXTIME_RECVD:     
 			unixtime = msg->recvd;
 			break;
@@ -719,6 +733,8 @@
 		case M_HOUR_STAMP:    
 		case M_MIN_STAMP:     
 		case M_SEC_STAMP:     
+		case M_TZOFFSET_STAMP:
+		case M_TZ_STAMP:
 		case M_UNIXTIME_STAMP:     
 			unixtime = msg->stamp;
 	                break;
@@ -783,6 +799,16 @@
  	        case M_DATE_STAMP:
 	                length = strftime(*dest, *left - 1, "%h %e %H:%M:%S", tm);
 	                break;
+	        case M_TZOFFSET:
+ 	        case M_TZOFFSET_RECVD:
+ 	        case M_TZOFFSET_STAMP:
+			length = strftime(*dest, *left -1, "%z", tm);
+			break;
+	        case M_TZ:
+ 	        case M_TZ_RECVD:
+ 	        case M_TZ_STAMP:
+			length = strftime(*dest, *left -1, "%Z", tm);
+			break;
 	        case M_UNIXTIME:
  	        case M_UNIXTIME_RECVD:
  	        case M_UNIXTIME_STAMP:
@@ -823,6 +849,8 @@
 		{ "SEC", M_SEC },
 		{ "WEEKDAY", M_WEEKDAY },
 		{ "UNIXTIME", M_UNIXTIME },
+		{ "TZOFFSET", M_TZOFFSET },
+		{ "TZ", M_TZ },
 
  		{ "R_DATE", M_DATE_RECVD },
  		{ "R_FULLDATE", M_FULLDATE_RECVD },
@@ -835,6 +863,8 @@
  		{ "R_SEC", M_SEC_RECVD },
  		{ "R_WEEKDAY", M_WEEKDAY_RECVD },
 		{ "R_UNIXTIME", M_UNIXTIME_RECVD },
+		{ "R_TZOFFSET", M_TZOFFSET_RECVD },
+		{ "R_TZ", M_TZ_RECVD },
  
  		{ "S_DATE", M_DATE_STAMP },
  		{ "S_FULLDATE", M_FULLDATE_STAMP },
@@ -847,6 +877,8 @@
  		{ "S_SEC", M_SEC_STAMP },
  		{ "S_WEEKDAY", M_WEEKDAY_STAMP },
  		{ "S_UNIXTIME", M_UNIXTIME_STAMP },
+ 		{ "S_TZOFFSET", M_TZOFFSET_STAMP },
+ 		{ "S_TZ", M_TZ_STAMP },
 		
 		{ "HOST_FROM", M_HOST_FROM },
 		{ "FULLHOST_FROM", M_FULLHOST_FROM },

--IS0zKkzwUGydFO0o--