Re: log rotate patch

"Christian Theil Have" <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
There is a stupid error in the patch (missing octstr_get_cstr). Sorry about
that. Here is an updated one.

Regards,
Christian Theil Have

On Mon, Sep 1, 2008 at 10:40 AM, Christian Theil Have <
[email protected]> wrote:

> Hi
>
> Attached is a patch (against latest CVS) that adds built-in support for log
> rotation. The code was written by Allan Frese against an older version of
> Kannel. I ported it to the CVS version and made this patch.
> The code has been running reliably for several years in the older version
> of Kannel.
>
> Best regards,
> Christian Theil Have
>
log-rotate.patch (application/octet-stream, 22.4 KB)
diff -urN --exclude=config.nice --exclude=c.sh --exclude=configure.in --exclude=config.status --exclude=config.log --exclude=ChangeLog --exclude='*~' --exclude=.depend --exclude='#*' --exclude=Makefile.in --exclude=Makefile --exclude=configure --exclude=aclocal.m4 --exclude=.deps --exclude=CVS --exclude=.svn ./gw/bearerbox.c ../mbuni-realtime/src/kannel-snapshot/gw/bearerbox.c
--- ./gw/bearerbox.c	2008-04-24 16:44:59.000000000 +0200
+++ ../mbuni-realtime/src/kannel-snapshot/gw/bearerbox.c	2008-09-01 09:06:10.000000000 +0200
@@ -352,6 +352,7 @@
 {
     CfgGroup *grp;
     Octstr *log, *val;
+    Octstr *log_rotate;
     long loglevel, store_dump_freq;
     int lf, m;
 #ifdef HAVE_LIBSSL
@@ -367,9 +368,13 @@
 
     log = cfg_get(grp, octstr_imm("log-file"));
     if (log != NULL) {
+        log_rotate = cfg_get(grp, octstr_imm("log-rotate"));
+        log_rotate = log_rotate ? log_rotate : octstr_imm("");
+
         if (cfg_get_integer(&loglevel, grp, octstr_imm("log-level")) == -1)
             loglevel = 0;
-        log_open(octstr_get_cstr(log), loglevel, GW_NON_EXCL);
+        log_open(octstr_get_cstr(log), loglevel, GW_NON_EXCL, octstr_get_cstr(log_rotate));
+        octstr_destroy(log_rotate);
         octstr_destroy(log);
     }
 
@@ -393,7 +398,10 @@
 
     /* open access-log file */
     if ((log = cfg_get(grp, octstr_imm("access-log"))) != NULL) {
-        alog_open(octstr_get_cstr(log), lf, m ? 0 : 1);
+        log_rotate = cfg_get(grp, octstr_imm("access-log-rotate"));
+        log_rotate = log_rotate ? log_rotate : octstr_imm("");
+        alog_open(octstr_get_cstr(log), lf, m ? 0 : 1, octstr_get_cstr(log_rotate));
+        octstr_destroy(log_rotate);
         octstr_destroy(log);
     }
 
diff -urN --exclude=config.nice --exclude=c.sh --exclude=configure.in --exclude=config.status --exclude=config.log --exclude=ChangeLog --exclude='*~' --exclude=.depend --exclude='#*' --exclude=Makefile.in --exclude=Makefile --exclude=configure --exclude=aclocal.m4 --exclude=.deps --exclude=CVS --exclude=.svn ./gw/smsbox.c ../mbuni-realtime/src/kannel-snapshot/gw/smsbox.c
--- ./gw/smsbox.c	2008-06-24 13:28:41.000000000 +0200
+++ ../mbuni-realtime/src/kannel-snapshot/gw/smsbox.c	2008-09-01 09:06:42.000000000 +0200
@@ -3295,6 +3295,7 @@
 {
     CfgGroup *grp;
     Octstr *logfile;
+    Octstr *log_rotate;
     Octstr *p;
     long lvl;
     Octstr *http_proxy_host = NULL;
@@ -3443,12 +3444,16 @@
         octstr_get_cstr(accepted_chars) : SENDSMS_DEFAULT_CHARS;
     logfile = cfg_get(grp, octstr_imm("log-file"));
 
+
     cfg_get_integer(&lvl, grp, octstr_imm("log-level"));
 
     if (logfile != NULL) {
 	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);
+        log_rotate = cfg_get(grp, octstr_imm("log-rotate"));
+        log_rotate = log_rotate ? log_rotate : octstr_imm("");
+        log_open(octstr_get_cstr(logfile), lvl, GW_NON_EXCL, octstr_get_cstr(log_rotate));
+        octstr_destroy(log_rotate);
 	octstr_destroy(logfile);
     }
     if (global_sender != NULL) {
@@ -3471,7 +3476,10 @@
     /* open access-log file */
     if ((p = cfg_get(grp, octstr_imm("access-log"))) != NULL) {
         info(0, "Logging accesses to '%s'.", octstr_get_cstr(p));
-        alog_open(octstr_get_cstr(p), lf, m ? 0 : 1);
+        log_rotate = cfg_get(grp, octstr_imm("access-log-rotate")); 
+        log_rotate = log_rotate ? log_rotate : octstr_imm("");
+        alog_open(octstr_get_cstr(p), lf, m ? 0 : 1, octstr_get_cstr(log_rotate));
+        octstr_destroy(log_rotate);
         octstr_destroy(p);
     }
 
diff -urN --exclude=config.nice --exclude=c.sh --exclude=configure.in --exclude=config.status --exclude=config.log --exclude=ChangeLog --exclude='*~' --exclude=.depend --exclude='#*' --exclude=Makefile.in --exclude=Makefile --exclude=configure --exclude=aclocal.m4 --exclude=.deps --exclude=CVS --exclude=.svn ./gw/smscconn.c ../mbuni-realtime/src/kannel-snapshot/gw/smscconn.c
--- ./gw/smscconn.c	2008-03-16 12:38:16.000000000 +0100
+++ ../mbuni-realtime/src/kannel-snapshot/gw/smscconn.c	2008-09-01 09:08:23.000000000 +0200
@@ -193,6 +193,7 @@
     GET_OPTIONAL_VAL(conn->unified_prefix, "unified-prefix");
     GET_OPTIONAL_VAL(conn->our_host, "our-host");
     GET_OPTIONAL_VAL(conn->log_file, "log-file");
+    GET_OPTIONAL_VAL(conn->log_rotate, "log-rotate");
     cfg_get_bool(&conn->alt_dcs, grp, octstr_imm("alt-dcs"));
 
     GET_OPTIONAL_VAL(allowed_smsc_id_regex, "allowed-smsc-id-regex");
@@ -234,8 +235,9 @@
 
     /* open a smsc-id specific log-file in exlusive mode */
     if (conn->log_file)
-        conn->log_idx = log_open(octstr_get_cstr(conn->log_file), 
-                                 conn->log_level, GW_EXCL); 
+        conn->log_idx = log_open(octstr_get_cstr(conn->log_file),
+                                 conn->log_level, GW_EXCL,
+				conn->log_rotate ? octstr_get_cstr(conn->log_rotate) : "");
 #undef GET_OPTIONAL_VAL
 #undef SPLIT_OPTIONAL_VAL
 
diff -urN --exclude=config.nice --exclude=c.sh --exclude=configure.in --exclude=config.status --exclude=config.log --exclude=ChangeLog --exclude='*~' --exclude=.depend --exclude='#*' --exclude=Makefile.in --exclude=Makefile --exclude=configure --exclude=aclocal.m4 --exclude=.deps --exclude=CVS --exclude=.svn ./gw/smscconn_p.h ../mbuni-realtime/src/kannel-snapshot/gw/smscconn_p.h
--- ./gw/smscconn_p.h	2008-03-16 12:38:16.000000000 +0100
+++ ../mbuni-realtime/src/kannel-snapshot/gw/smscconn_p.h	2008-08-29 15:29:05.000000000 +0200
@@ -188,6 +188,7 @@
     /* Our smsc specific log-file data */
     Octstr *log_file;
     long log_level;
+	Octstr *log_rotate;
     int log_idx;    /* index position within the global logfiles[] array in gwlib/log.c */
 
     long reconnect_delay; /* delay in seconds while re-connect attempts */
diff -urN --exclude=config.nice --exclude=c.sh --exclude=configure.in --exclude=config.status --exclude=config.log --exclude=ChangeLog --exclude='*~' --exclude=.depend --exclude='#*' --exclude=Makefile.in --exclude=Makefile --exclude=configure --exclude=aclocal.m4 --exclude=.deps --exclude=CVS --exclude=.svn ./gw/wapbox.c ../mbuni-realtime/src/kannel-snapshot/gw/wapbox.c
--- ./gw/wapbox.c	2008-01-09 21:06:57.000000000 +0100
+++ ../mbuni-realtime/src/kannel-snapshot/gw/wapbox.c	2008-09-01 09:07:19.000000000 +0200
@@ -125,6 +125,7 @@
     CfgGroup *grp;
     Octstr *s;
     Octstr *logfile;
+    Octstr *log_rotate;
     int lf, m;
 
     lf = m = 1;
@@ -160,11 +161,16 @@
     if (cfg_get_integer(&timer_freq, grp, octstr_imm("timer-freq")) == -1)
         timer_freq = DEFAULT_TIMER_FREQ;
 
+    
     logfile = cfg_get(grp, octstr_imm("log-file"));
     if (logfile != NULL) {
-        log_open(octstr_get_cstr(logfile), logfilelevel, GW_NON_EXCL);
+        log_rotate = cfg_get(grp, octstr_imm("log-rotate"));
+        log_rotate = log_rotate ? log_rotate : octstr_imm("");
+        log_open(octstr_get_cstr(logfile), logfilelevel, GW_NON_EXCL,
+			octstr_get_cstr(log_rotate));
         info(0, "Starting to log to file %s level %ld", 
              octstr_get_cstr(logfile), logfilelevel);
+	octstr_destroy(log_rotate);
     }
     octstr_destroy(logfile);
 
@@ -195,9 +201,12 @@
 
     /* open access-log file */
     if ((s = cfg_get(grp, octstr_imm("access-log"))) != NULL) {
+        log_rotate = cfg_get(grp, octstr_imm("access-log-rotate"));
+        log_rotate = log_rotate ? log_rotate : octstr_imm("");
         info(0, "Logging accesses to '%s'.", octstr_get_cstr(s));
-        alog_open(octstr_get_cstr(s), lf, m ? 0 : 1);
+        alog_open(octstr_get_cstr(s), lf, m ? 0 : 1, octstr_get_cstr(log_rotate));
         octstr_destroy(s);
+        octstr_destroy(log_rotate);
     }
 
     /* configure the 'wtls' group */
diff -urN --exclude=config.nice --exclude=c.sh --exclude=configure.in --exclude=config.status --exclude=config.log --exclude=ChangeLog --exclude='*~' --exclude=.depend --exclude='#*' --exclude=Makefile.in --exclude=Makefile --exclude=configure --exclude=aclocal.m4 --exclude=.deps --exclude=CVS --exclude=.svn ./gwlib/accesslog.c ../mbuni-realtime/src/kannel-snapshot/gwlib/accesslog.c
--- ./gwlib/accesslog.c	2008-01-09 21:06:56.000000000 +0100
+++ ../mbuni-realtime/src/kannel-snapshot/gwlib/accesslog.c	2008-08-29 16:07:54.000000000 +0200
@@ -76,6 +76,9 @@
 static char filename[FILENAME_MAX + 1]; /* to allow re-open */
 static int use_localtime;
 static int markers = 1;     /* can be turned-off by 'access-log-clean = yes' */
+static enum { NEVER = 0, DAILY, WEEKLY, MONTHLY } rotate_logfile = NEVER;
+static struct tm rotate_tm;
+static int init_rotate_tm = 1;
 
 /*
  * Reopen/rotate lock.
@@ -126,7 +129,7 @@
 }
 
 
-void alog_open(char *fname, int use_localtm, int use_markers)
+void alog_open(char *fname, int use_localtm, int use_markers, char *rotatelog)
 {
     FILE *f;
     
@@ -145,6 +148,16 @@
     if (writers == NULL)
         writers = gwlist_create();
 
+	rotate_logfile = NEVER;
+	if (rotatelog && *rotatelog) {
+		if (strcmp(rotatelog, "daily") == 0)
+			rotate_logfile = DAILY;
+		else if (strcmp(rotatelog, "weekly") == 0)
+			rotate_logfile = WEEKLY;
+		else if (strcmp(rotatelog, "monthly") == 0)
+			rotate_logfile = MONTHLY;
+	}
+
     f = fopen(fname, "a");
     if (f == NULL) {
         error(errno, "Couldn't open logfile `%s'.", fname);
@@ -218,6 +231,54 @@
     gwlist_add_producer(writers);
     gwlist_unlock(writers);
 
+	if (rotate_logfile != NEVER) {
+		int do_rotate = NEVER;
+		time_t t;
+		struct tm tm;
+
+		time(&t);
+		if (use_localtime)
+			tm = gw_localtime(t);
+		else
+			tm = gw_gmtime(t);
+		if (init_rotate_tm) {
+			rotate_tm = tm;
+			init_rotate_tm = 0;
+		}
+
+		do_rotate |= ((rotate_logfile == DAILY  ));
+		do_rotate |= ((rotate_logfile == WEEKLY ) && (tm.tm_wday == 1));
+		do_rotate |= ((rotate_logfile == MONTHLY) && (tm.tm_mday == 1));
+		do_rotate &= (rotate_tm.tm_mday != tm.tm_mday);
+
+		if (do_rotate) {
+			char log_start[16];
+			char new_filename[FILENAME_MAX + 1];
+			int year, mon, mday;
+
+			rotate_tm = tm;
+			year = tm.tm_year+1900; mon = tm.tm_mon+1; mday = tm.tm_mday-1;
+			if (mday < 1) {
+				mon--;
+				if (mon < 1) {
+					mon = 12;
+					year--;
+				}
+				mday = 31;
+				if (mon < 8 && ((mon & 0x01) == 0)) mday = 30;
+				if (mon > 7 && ((mon & 0x01) == 1)) mday = 30;
+				if (mon == 2)
+					mday = (year % 4) ? 28 : 29;     // Works until 12/31/2099 ;-)
+			}
+
+			fclose(file);
+			sprintf(new_filename, "%s.%04d-%02d-%02d", filename, year, mon, mday);
+			if (rename(filename, new_filename) == -1)
+				warning(0, "Log rotate (%) failed, continuing in current logfile", filename);
+			file = fopen(filename, "a");
+		}
+	}
+
     vfprintf(file, buf, args);
     fflush(file);
 
diff -urN --exclude=config.nice --exclude=c.sh --exclude=configure.in --exclude=config.status --exclude=config.log --exclude=ChangeLog --exclude='*~' --exclude=.depend --exclude='#*' --exclude=Makefile.in --exclude=Makefile --exclude=configure --exclude=aclocal.m4 --exclude=.deps --exclude=CVS --exclude=.svn ./gwlib/accesslog.h ../mbuni-realtime/src/kannel-snapshot/gwlib/accesslog.h
--- ./gwlib/accesslog.h	2008-01-09 21:06:56.000000000 +0100
+++ ../mbuni-realtime/src/kannel-snapshot/gwlib/accesslog.h	2008-08-29 15:45:25.000000000 +0200
@@ -75,7 +75,7 @@
 /* open access log with filename fname. if use_localtime != 0 then
  * all events are logged with localtime, not GMT
  */
-void alog_open(char *fname, int use_localtime, int use_markers);
+void alog_open(char *fname, int use_localtime, int use_markers, char *rotatelog);
 
 /* close access log. Do nothing if no open file */
 void alog_close(void);
diff -urN --exclude=config.nice --exclude=c.sh --exclude=configure.in --exclude=config.status --exclude=config.log --exclude=ChangeLog --exclude='*~' --exclude=.depend --exclude='#*' --exclude=Makefile.in --exclude=Makefile --exclude=configure --exclude=aclocal.m4 --exclude=.deps --exclude=CVS --exclude=.svn ./gwlib/cfg.def ../mbuni-realtime/src/kannel-snapshot/gwlib/cfg.def
--- ./gwlib/cfg.def	2008-07-26 11:21:17.000000000 +0200
+++ ../mbuni-realtime/src/kannel-snapshot/gwlib/cfg.def	2008-09-01 09:11:02.000000000 +0200
@@ -94,10 +94,12 @@
     OCTSTR(wdp-interface-name)
     OCTSTR(log-file)
     OCTSTR(log-level)
+    OCTSTR(log-rotate)
     OCTSTR(access-log)
     OCTSTR(access-log-time)
     OCTSTR(access-log-format)
     OCTSTR(access-log-clean)
+    OCTSTR(access-log-rotate)
     OCTSTR(store-file)
     OCTSTR(store-dump-freq)
     OCTSTR(store-type)
@@ -150,11 +152,13 @@
     OCTSTR(device-home)
     OCTSTR(log-file)
     OCTSTR(log-level)
+    OCTSTR(log-rotate)
     OCTSTR(syslog-level)
     OCTSTR(smart-errors)
     OCTSTR(access-log)
     OCTSTR(access-log-time)
     OCTSTR(access-log-clean)
+    OCTSTR(access-log-rotate)
     OCTSTR(http-interface-name)
     OCTSTR(concatenation)
     OCTSTR(max-messages)
@@ -261,9 +265,11 @@
     OCTSTR(global-sender)
     OCTSTR(log-file)
     OCTSTR(log-level)
+    OCTSTR(log-rotate)
     OCTSTR(access-log)
     OCTSTR(access-log-time)
     OCTSTR(access-log-clean)
+    OCTSTR(access-log-rotate)
     OCTSTR(sms-length)
     OCTSTR(reply-couldnotfetch)
     OCTSTR(reply-couldnotrepresent)
@@ -306,6 +312,7 @@
     OCTSTR(reroute-dlr)
     OCTSTR(log-file)
     OCTSTR(log-level)
+    OCTSTR(log-rotate)
     OCTSTR(our-host)
     OCTSTR(alt-dcs)
     OCTSTR(throughput)
diff -urN --exclude=config.nice --exclude=c.sh --exclude=configure.in --exclude=config.status --exclude=config.log --exclude=ChangeLog --exclude='*~' --exclude=.depend --exclude='#*' --exclude=Makefile.in --exclude=Makefile --exclude=configure --exclude=aclocal.m4 --exclude=.deps --exclude=CVS --exclude=.svn ./gwlib/log.c ../mbuni-realtime/src/kannel-snapshot/gwlib/log.c
--- ./gwlib/log.c	2008-01-09 21:06:55.000000000 +0100
+++ ../mbuni-realtime/src/kannel-snapshot/gwlib/log.c	2008-08-29 15:32:00.000000000 +0200
@@ -109,6 +109,10 @@
     enum excl_state exclusive;
 } logfiles[MAX_LOGFILES];
 static int num_logfiles = 0;
+static enum { NEVER = 0, DAILY, WEEKLY, MONTHLY } rotate_logfile = NEVER;
+static struct tm rotate_tm;
+static int init_rotate_tm = 1;
+static char *rotatelog = NULL;
 
 
 /*
@@ -154,6 +158,16 @@
 {
     int i;
 
+    // rotate_logfile = NEVER;
+    if (rotate_logfile == NEVER && rotatelog && *rotatelog) {
+		if (strcmp(rotatelog, "daily") == 0)
+	    	rotate_logfile = DAILY;
+		else if (strcmp(rotatelog, "weekly") == 0)
+	    	rotate_logfile = WEEKLY;
+		else if (strcmp(rotatelog, "monthly") == 0)
+	    	rotate_logfile = MONTHLY;
+    }
+
     for (i = 0; i < num_logfiles; ++i)
 	if (logfiles[i].file == stderr)
 	    return;
@@ -298,13 +312,15 @@
 }
 
 
-int log_open(char *filename, int level, enum excl_state excl)
+int log_open(char *filename, int level, enum excl_state excl, char *do_rotatelog)
 {
     FILE *f = NULL;
     int i;
     
     gw_rwlock_wrlock(&rwlock);
 
+	rotatelog = gw_strdup(do_rotatelog);
+
     if (num_logfiles == MAX_LOGFILES) {
         gw_rwlock_unlock(&rwlock);
         error(0, "Too many log files already open, not adding `%s'",
@@ -414,6 +430,59 @@
 
 static void PRINTFLIKE(2,0) output(FILE *f, char *buf, va_list args) 
 {
+	int i = (int)f;
+	
+	if (rotate_logfile != NEVER && logfiles[i].file != stderr) {
+		int do_rotate = NEVER;
+		time_t t;
+		struct tm tm;
+
+        time(&t);
+#if LOG_TIMESTAMP_LOCALTIME
+		tm = gw_localtime(t);
+#else
+        tm = gw_gmtime(t);
+#endif
+		if (init_rotate_tm) {
+			rotate_tm = tm;
+			init_rotate_tm = 0;
+		}
+
+		do_rotate |= ((rotate_logfile == DAILY  ));
+		do_rotate |= ((rotate_logfile == WEEKLY ) && (tm.tm_wday == 1));
+		do_rotate |= ((rotate_logfile == MONTHLY) && (tm.tm_mday == 1));
+		do_rotate &= (rotate_tm.tm_mday != tm.tm_mday);
+
+		if (do_rotate) {
+			char log_start[16];
+			char new_filename[FILENAME_MAX + 1];
+			int year, mon, mday;
+
+			rotate_tm = tm;
+			year = tm.tm_year+1900; mon = tm.tm_mon+1; mday = tm.tm_mday-1;
+			if (mday < 1) {
+				mon--;
+				if (mon < 1) {
+					mon = 12;
+					year--;
+				}
+				mday = 31;
+				if (mon < 8 && ((mon & 0x01) == 0)) mday = 30;
+				if (mon > 7 && ((mon & 0x01) == 1)) mday = 30;
+				if (mon == 2)
+					mday = (year % 4) ? 28 : 29;     // Works until 12/31/2099 ;-)
+			}
+
+			fclose(logfiles[i].file);
+			sprintf(new_filename, "%s.%04d-%02d-%02d",
+				logfiles[i].filename, year, mon, mday);
+			if (rename(logfiles[i].filename, new_filename) == -1)
+				warning(0, "Log rotate (%s) failed, continuing in current logfile",
+					logfiles[i].filename);
+			logfiles[i].file = fopen(logfiles[i].filename, "a");
+		}
+    }
+	
     vfprintf(f, buf, args);
     fflush(f);
 }
diff -urN --exclude=config.nice --exclude=c.sh --exclude=configure.in --exclude=config.status --exclude=config.log --exclude=ChangeLog --exclude='*~' --exclude=.depend --exclude='#*' --exclude=Makefile.in --exclude=Makefile --exclude=configure --exclude=aclocal.m4 --exclude=.deps --exclude=CVS --exclude=.svn ./gwlib/log.h ../mbuni-realtime/src/kannel-snapshot/gwlib/log.h
--- ./gwlib/log.h	2008-01-09 21:06:55.000000000 +0100
+++ ../mbuni-realtime/src/kannel-snapshot/gwlib/log.h	2008-08-29 14:30:53.000000000 +0200
@@ -149,7 +149,7 @@
    Where `excl' defines if the log file will be exclusive or not.
    Returns the index within the global logfiles[] array where this
    log file entry has been added. */
-int log_open(char *filename, int level, enum excl_state excl);
+int log_open(char *filename, int level, enum excl_state excl, char *rotatelog);
 
 /* Close and re-open all logfiles */
 void log_reopen(void);
diff -urN --exclude=config.nice --exclude=c.sh --exclude=configure.in --exclude=config.status --exclude=config.log --exclude=ChangeLog --exclude='*~' --exclude=.depend --exclude='#*' --exclude=Makefile.in --exclude=Makefile --exclude=configure --exclude=aclocal.m4 --exclude=.deps --exclude=CVS --exclude=.svn ./gwlib/utils.c ../mbuni-realtime/src/kannel-snapshot/gwlib/utils.c
--- ./gwlib/utils.c	2008-01-09 21:06:54.000000000 +0100
+++ ../mbuni-realtime/src/kannel-snapshot/gwlib/utils.c	2008-08-29 15:32:54.000000000 +0200
@@ -438,6 +438,7 @@
     int debug_lvl = -1;
     int file_lvl = GW_DEBUG;
     char *log_file = NULL;
+	char *log_rotate = NULL;
     char *debug_places = NULL;
     char *panic_script = NULL, *user = NULL;
     int parachute = 0, daemonize = 0;
@@ -460,7 +461,13 @@
                 file_lvl = atoi(argv[i+1]);
                 i++;
             } else
-                panic(0, "Missing argument for option %s\n", argv[i]); 
+                panic(0, "Missing argument for option %s\n", argv[i]);
+		} else if (strcmp(argv[i],"-R")==0 || strcmp(argv[i],"--logrotate")==0) {
+		    if (i+1 < argc && *(argv[i+1]) != '-') {
+				log_rotate = argv[i+1];
+				i++;
+		    } else
+				fprintf(stderr, "Missing argument for option %s\n", argv[i]);
         } else if (strcmp(argv[i],"-D")==0 || strcmp(argv[i],"--debug")==0) {
             if (i+1 < argc) {
                 debug_places = argv[i+1];
@@ -545,10 +552,10 @@
     if (debug_places != NULL)
         log_set_debug_places(debug_places);
     if (log_file != NULL)
-        log_open(log_file, file_lvl, GW_NON_EXCL);
+        log_open(log_file, file_lvl, GW_NON_EXCL, log_rotate ? log_rotate : "");
 
-    info(0, "Debug_lvl = %d, log_file = %s, log_lvl = %d",
-         debug_lvl, log_file ? log_file : "<none>", file_lvl);
+    info(0, "Debug_lvl = %d, log_file = %s, log_lvl = %d, log_rotate = %s",
+         debug_lvl, log_file ? log_file : "<none>", file_lvl, log_rotate ? log_rotate : "never");
     if (debug_places != NULL)
 	    info(0, "Debug places: `%s'", debug_places);
 
diff -urN --exclude=config.nice --exclude=c.sh --exclude=configure.in --exclude=config.status --exclude=config.log --exclude=ChangeLog --exclude='*~' --exclude=.depend --exclude='#*' --exclude=Makefile.in --exclude=Makefile --exclude=configure --exclude=aclocal.m4 --exclude=.deps --exclude=CVS --exclude=.svn ./test/drive_smpp.c ../mbuni-realtime/src/kannel-snapshot/test/drive_smpp.c
--- ./test/drive_smpp.c	2008-01-09 21:06:54.000000000 +0100
+++ ../mbuni-realtime/src/kannel-snapshot/test/drive_smpp.c	2008-08-29 15:40:27.000000000 +0200
@@ -526,7 +526,7 @@
     }
 
     if (log_file != NULL)
-    	log_open(log_file, GW_DEBUG, GW_NON_EXCL);
+    	log_open(log_file, GW_DEBUG, GW_NON_EXCL, "");
 
     info(0, "Starting drive_smpp test.");
     gwthread_create(accept_thread, &port);
diff -urN --exclude=config.nice --exclude=c.sh --exclude=configure.in --exclude=config.status --exclude=config.log --exclude=ChangeLog --exclude='*~' --exclude=.depend --exclude='#*' --exclude=Makefile.in --exclude=Makefile --exclude=configure --exclude=aclocal.m4 --exclude=.deps --exclude=CVS --exclude=.svn ./test/test_http_server.c ../mbuni-realtime/src/kannel-snapshot/test/test_http_server.c
--- ./test/test_http_server.c	2008-01-09 21:06:53.000000000 +0100
+++ ../mbuni-realtime/src/kannel-snapshot/test/test_http_server.c	2008-08-29 15:40:58.000000000 +0200
@@ -395,7 +395,7 @@
     }
 
     if (log_filename != NULL) {
-    	log_open(octstr_get_cstr(log_filename), GW_DEBUG, GW_NON_EXCL);
+    	log_open(octstr_get_cstr(log_filename), GW_DEBUG, GW_NON_EXCL, "");
 	    octstr_destroy(log_filename);
     }
 
diff -urN --exclude=config.nice --exclude=c.sh --exclude=configure.in --exclude=config.status --exclude=config.log --exclude=ChangeLog --exclude='*~' --exclude=.depend --exclude='#*' --exclude=Makefile.in --exclude=Makefile --exclude=configure --exclude=aclocal.m4 --exclude=.deps --exclude=CVS --exclude=.svn ./test/test_pap.c ../mbuni-realtime/src/kannel-snapshot/test/test_pap.c
--- ./test/test_pap.c	2008-01-09 21:06:53.000000000 +0100
+++ ../mbuni-realtime/src/kannel-snapshot/test/test_pap.c	2008-08-29 15:41:09.000000000 +0200
@@ -118,7 +118,7 @@
     }
 
     if (log_file != NULL) {
-    	log_open(octstr_get_cstr(log_file), GW_DEBUG, GW_NON_EXCL);
+    	log_open(octstr_get_cstr(log_file), GW_DEBUG, GW_NON_EXCL, "");
 	octstr_destroy(log_file);
     }
 
diff -urN --exclude=config.nice --exclude=c.sh --exclude=configure.in --exclude=config.status --exclude=config.log --exclude=ChangeLog --exclude='*~' --exclude=.depend --exclude='#*' --exclude=Makefile.in --exclude=Makefile --exclude=configure --exclude=aclocal.m4 --exclude=.deps --exclude=CVS --exclude=.svn ./test/wml_tester.c ../mbuni-realtime/src/kannel-snapshot/test/wml_tester.c
--- ./test/wml_tester.c	2008-01-09 21:06:53.000000000 +0100
+++ ../mbuni-realtime/src/kannel-snapshot/test/wml_tester.c	2008-08-29 15:41:23.000000000 +0200
@@ -205,7 +205,7 @@
 
 	    if (file && outputti != BINARY_OUT) {
 		fclose(fp);
-		log_open(octstr_get_cstr(filename), 0, GW_NON_EXCL);
+		log_open(octstr_get_cstr(filename), 0, GW_NON_EXCL, "");
 		octstr_dump(wml_binary, 0);
 		log_close_all();
 		fp = fopen(octstr_get_cstr(filename), "a");
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.