patch attached.

On Wed, 2003-07-30 at 10:13, Alan McNatty wrote:
> Hello,
> 
> I have attached a small patch to add syslog logging support for both
> smsbox and bearerbox as was done for wapbox some time ago. I have made
> some minor changes to gwlib/log.c to reformat in case of syslog logging
> to exclude the date stamp which syslog prepends. Also a tiny change to
> actually get the wapbox syslogging to work I believe. 
> 
> Please comment/vote, etc ...
-- 
Alan McNatty <[EMAIL PROTECTED]>
Index: gw/bearerbox.c
===================================================================
RCS file: /home/cvs/gateway/gw/bearerbox.c,v
retrieving revision 1.142
diff -u -B -w -r1.142 bearerbox.c
--- gw/bearerbox.c	23 Jul 2003 12:05:38 -0000	1.142
+++ gw/bearerbox.c	29 Jul 2003 06:32:04 -0000
@@ -306,7 +306,25 @@
 	if (cfg_get_integer(&loglevel, grp, octstr_imm("log-level")) == -1)
 	    loglevel = 0;
 	log_open(octstr_get_cstr(log), loglevel, GW_NON_EXCL);
+    }
 	octstr_destroy(log);
+
+    if ((log = cfg_get(grp, octstr_imm("syslog-level"))) != NULL) {
+	long loglevel;
+		                                                                                    
+	if (octstr_compare(log, octstr_imm("none")) == 0) {
+	    log_set_syslog(NULL, 0);
+	    debug("bb", 0, "syslog parameter is none");
+	} else if (octstr_parse_long(&loglevel, log, 0, 0) != -1) {
+	    log_set_syslog("bearerbox", loglevel);
+	    debug("bb", 0, "syslog parameter is %ld", loglevel);
+	} else
+	    debug("bb", 0, "unrecognised syslog parameter %ld", loglevel);
+
+	octstr_destroy(log);
+    } else {
+	log_set_syslog(NULL, 0);
+	debug("bb", 0, "no syslog parameter");
     }
 
     if (check_config(cfg) == -1)
Index: gw/smsbox.c
===================================================================
RCS file: /home/cvs/gateway/gw/smsbox.c,v
retrieving revision 1.227
diff -u -B -w -r1.227 smsbox.c
--- gw/smsbox.c	20 Jul 2003 22:05:28 -0000	1.227
+++ gw/smsbox.c	29 Jul 2003 06:32:31 -0000
@@ -3221,8 +3221,27 @@
 	info(0, "Starting to log to file %s level %ld", 
 	     octstr_get_cstr(logfile), lvl);
 	log_open(octstr_get_cstr(logfile), lvl, GW_NON_EXCL);
+    }
 	octstr_destroy(logfile);
+
+    if ((p = cfg_get(grp, octstr_imm("syslog-level"))) != NULL) {
+	long level;
+		                                                                                    
+        if (octstr_compare(p, octstr_imm("none")) == 0) {
+            log_set_syslog(NULL, 0);
+	    debug("sms", 0, "syslog parameter is none");
+        } else if (octstr_parse_long(&level, p, 0, 0) != -1) {
+	    log_set_syslog("smsbox", level);
+	    debug("sms", 0, "syslog parameter is %ld", level);
+        } else
+	    debug("sms", 0, "unrecognised syslog parameter %ld", level);
+
+	octstr_destroy(p);
+    } else {
+	log_set_syslog(NULL, 0);
+	debug("sms", 0, "no syslog parameter");
     }
+    
     if (global_sender != NULL) {
 	info(0, "Service global sender set as '%s'", 
 	     octstr_get_cstr(global_sender));
Index: gw/wapbox.c
===================================================================
RCS file: /home/cvs/gateway/gw/wapbox.c,v
retrieving revision 1.164
diff -u -B -w -r1.164 wapbox.c
--- gw/wapbox.c	27 Jul 2003 14:18:52 -0000	1.164
+++ gw/wapbox.c	29 Jul 2003 06:32:37 -0000
@@ -114,10 +114,12 @@
         if (octstr_compare(s, octstr_imm("none")) == 0) {
             log_set_syslog(NULL, 0);
             debug("wap", 0, "syslog parameter is none");
-        } else if (octstr_parse_long(&level, s, 0, 0) == -1) {
+        } else if (octstr_parse_long(&level, s, 0, 0) != -1) {
             log_set_syslog("wapbox", level);
             debug("wap", 0, "syslog parameter is %ld", level);
-        }
+        } else
+            debug("wap", 0, "unrecognised syslog parameter %ld", level);
+
         octstr_destroy(s);
     } else {
         log_set_syslog(NULL, 0);
Index: gwlib/cfg.def
===================================================================
RCS file: /home/cvs/gateway/gwlib/cfg.def,v
retrieving revision 1.91
diff -u -B -w -r1.91 cfg.def
--- gwlib/cfg.def	27 Jul 2003 14:48:02 -0000	1.91
+++ gwlib/cfg.def	29 Jul 2003 06:32:40 -0000
@@ -37,6 +37,7 @@
     OCTSTR(wdp-interface-name)
     OCTSTR(log-file)
     OCTSTR(log-level)
+    OCTSTR(syslog-level)
     OCTSTR(access-log)
     OCTSTR(store-file)
     OCTSTR(unified-prefix)
@@ -178,6 +179,7 @@
     OCTSTR(global-sender)
     OCTSTR(log-file)
     OCTSTR(log-level)
+    OCTSTR(syslog-level)
     OCTSTR(access-log)
     OCTSTR(sms-length)
     OCTSTR(reply-couldnotfetch)
Index: gwlib/log.c
===================================================================
RCS file: /home/cvs/gateway/gwlib/log.c,v
retrieving revision 1.37
diff -u -B -w -r1.37 log.c
--- gwlib/log.c	19 Jun 2003 18:01:44 -0000	1.37
+++ gwlib/log.c	29 Jul 2003 06:32:43 -0000
@@ -10,6 +10,8 @@
 #include <stdarg.h>
 #include <string.h>
 
+#include "config.h"
+
 #if HAVE_SYSLOG_H
 #include <syslog.h>
 #else
@@ -259,6 +261,11 @@
     char *p, prefix[1024];
     
     p = prefix;
+
+    /* Note: we'll use a null 'place' for syslog so 
+     * we can exclude the date stamp and place */
+    if ( place != NULL ) {
+
     time(&t);
 #if LOG_TIMESTAMP_LOCALTIME
     tm = gw_localtime(t);
@@ -270,6 +277,8 @@
     tm.tm_hour, tm.tm_min, tm.tm_sec);
     
     p = strchr(p, '\0');
+    }
+
     sprintf(p, "[%ld] ", gwthread_self());
     
     p = strchr(p, '\0');
@@ -357,6 +366,7 @@
 	    va_list args; \
 	    \
 	    add_stderr(); \
+	    \
 	    format(buf, level, place, e, fmt); \
 	    for (i = 0; i < num_logfiles; ++i) { \
 		if (logfiles[i].exclusive == GW_NON_EXCL && \
@@ -368,6 +378,7 @@
 		} \
 	    } \
 	    if (dosyslog) { \
+	        format(buf, level, NULL, e, fmt); \
 		va_start(args, fmt); \
 		kannel_syslog(buf,args,level); \
 		va_end(args); \

Reply via email to