[asterisk-commits] file: trunk r44172 - in /trunk: CHANGES configs/logger.conf.sample main/logger.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Oct 2 10:54:22 MST 2006


Author: file
Date: Mon Oct  2 12:54:21 2006
New Revision: 44172

URL: http://svn.digium.com/view/asterisk?rev=44172&view=rev
Log:
Add option to logger to rename log files with timestamp (issue #8020 reported by jmls)

Modified:
    trunk/CHANGES
    trunk/configs/logger.conf.sample
    trunk/main/logger.c

Modified: trunk/CHANGES
URL: http://svn.digium.com/view/asterisk/trunk/CHANGES?rev=44172&r1=44171&r2=44172&view=diff
==============================================================================
--- trunk/CHANGES (original)
+++ trunk/CHANGES Mon Oct  2 12:54:21 2006
@@ -19,3 +19,5 @@
      and/or H.450 supplementary service)
   * Added keepstats option to queues.conf which will keep queue
      statistics during a reload.
+  * Added rotatetimestamp option to logger.conf which will use
+     the time to name the logger files instead of sequence number.

Modified: trunk/configs/logger.conf.sample
URL: http://svn.digium.com/view/asterisk/trunk/configs/logger.conf.sample?rev=44172&r1=44171&r2=44172&view=diff
==============================================================================
--- trunk/configs/logger.conf.sample (original)
+++ trunk/configs/logger.conf.sample Mon Oct  2 12:54:21 2006
@@ -23,6 +23,11 @@
 ; Set the queue_log filename
 ; (defaults to queue_log)
 ;queue_log_name = queue_log
+;
+; Rename the logfiles using a timestamp instead of a
+; sequence number when "logger rotate" is executed
+; (defaults to no).
+;rotatetimestamp = yes
 ;
 ; This determines whether or not we log generic events to a file
 ; (defaults to yes).

Modified: trunk/main/logger.c
URL: http://svn.digium.com/view/asterisk/trunk/main/logger.c?rev=44172&r1=44171&r2=44172&view=diff
==============================================================================
--- trunk/main/logger.c (original)
+++ trunk/main/logger.c Mon Oct  2 12:54:21 2006
@@ -87,6 +87,7 @@
 
 static int filesize_reload_needed = 0;
 static int global_logmask = -1;
+static int rotatetimestamp = 0;
 
 static struct {
 	unsigned int queue_log:1;
@@ -340,6 +341,8 @@
 		logfiles.event_log = ast_true(s);
 	if ((s = ast_variable_retrieve(cfg, "general", "queue_log_name")))
 		ast_copy_string(queue_log_name, s, sizeof(queue_log_name));
+	if ((s = ast_variable_retrieve(cfg, "general", "rotatetimestamp")))
+		rotatetimestamp = ast_true(s);
 
 	AST_LIST_LOCK(&logchannels);
 	var = ast_variable_browse(cfg, "logfiles");
@@ -404,38 +407,44 @@
 			f->fileptr = NULL;
 			if (rotate) {
 				ast_copy_string(old, f->filename, sizeof(old));
+				
+				if (!rotatetimestamp) { 
+					for (x = 0; ; x++) {
+						snprintf(new, sizeof(new), "%s.%d", f->filename, x);
+						myf = fopen((char *)new, "r");
+						if (myf)
+							fclose(myf);
+						else
+							break;
+					}
+				} else 
+					snprintf(new, sizeof(new), "%s.%ld", f->filename, (long)time(NULL));
+
+				/* do it */
+				if (rename(old,new))
+					fprintf(stderr, "Unable to rename file '%s' to '%s'\n", old, new);
+			}
+		}
+	}
+
+	filesize_reload_needed = 0;
 	
-				for (x = 0; ; x++) {
-					snprintf(new, sizeof(new), "%s.%d", f->filename, x);
+	init_logger_chain();
+
+	if (logfiles.event_log) {
+		snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR, EVENTLOG);
+		if (event_rotate) {
+			if (!rotatetimestamp) { 
+				for (x=0;;x++) {
+					snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR, EVENTLOG,x);
 					myf = fopen((char *)new, "r");
-					if (myf)
+					if (myf) 	/* File exists */
 						fclose(myf);
 					else
 						break;
 				}
-	    
-				/* do it */
-				if (rename(old,new))
-					fprintf(stderr, "Unable to rename file '%s' to '%s'\n", old, new);
-			}
-		}
-	}
-
-	filesize_reload_needed = 0;
-	
-	init_logger_chain();
-
-	if (logfiles.event_log) {
-		snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR, EVENTLOG);
-		if (event_rotate) {
-			for (x=0;;x++) {
-				snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR, EVENTLOG,x);
-				myf = fopen((char *)new, "r");
-				if (myf) 	/* File exists */
-					fclose(myf);
-				else
-					break;
-			}
+			} else 
+				snprintf(new, sizeof(new), "%s/%s.%ld", (char *)ast_config_AST_LOG_DIR, EVENTLOG,(long)time(NULL));
 	
 			/* do it */
 			if (rename(old,new))
@@ -456,15 +465,18 @@
 	if (logfiles.queue_log) {
 		snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR, queue_log_name);
 		if (queue_rotate) {
-			for (x = 0; ; x++) {
-				snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR, queue_log_name, x);
-				myf = fopen((char *)new, "r");
-				if (myf) 	/* File exists */
-					fclose(myf);
-				else
-					break;
-			}
+			if (!rotatetimestamp) { 
+				for (x = 0; ; x++) {
+					snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR, queue_log_name, x);
+					myf = fopen((char *)new, "r");
+					if (myf) 	/* File exists */
+						fclose(myf);
+					else
+						break;
+				}
 	
+			} else 
+				snprintf(new, sizeof(new), "%s/%s.%ld", (char *)ast_config_AST_LOG_DIR, queue_log_name,(long)time(NULL));
 			/* do it */
 			if (rename(old, new))
 				ast_log(LOG_ERROR, "Unable to rename file '%s' to '%s'\n", old, new);



More information about the asterisk-commits mailing list