[svn-commits] murf: branch 1.2 r42200 - /branches/1.2/logger.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Wed Sep 6 19:14:14 MST 2006


Author: murf
Date: Wed Sep  6 21:14:14 2006
New Revision: 42200

URL: http://svn.digium.com/view/asterisk?rev=42200&view=rev
Log:
This should fix the problem reported in 7564: logger config file errors getting lost because logging isn't configured yet. The problem was that the code that exists to handle this case was not getting reached, because other tests were causing an early return from ast_log().

Modified:
    branches/1.2/logger.c

Modified: branches/1.2/logger.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/logger.c?rev=42200&r1=42199&r2=42200&view=diff
==============================================================================
--- branches/1.2/logger.c (original)
+++ branches/1.2/logger.c Wed Sep  6 21:14:14 2006
@@ -305,6 +305,7 @@
 	ast_mutex_unlock(&loglock);
 	
 	global_logmask = 0;
+	errno = 0;
 	/* close syslog */
 	closelog();
 	
@@ -312,7 +313,10 @@
 	
 	/* If no config file, we're fine, set default options. */
 	if (!cfg) {
-		fprintf(stderr, "Unable to open logger.conf: %s\n", strerror(errno));
+		if (errno)
+			fprintf(stderr, "Unable to open logger.conf: %s; default settings will be used.\n", strerror(errno));
+		else
+			fprintf(stderr, "Errors detected in logger.conf: see above; default settings will be used.\n");
 		chan = malloc(sizeof(struct logchannel));
 		memset(chan, 0, sizeof(struct logchannel));
 		chan->type = LOGTYPE_CONSOLE;
@@ -696,99 +700,8 @@
 
 	va_list ap;
 	
-	/* don't display LOG_DEBUG messages unless option_verbose _or_ option_debug
-	   are non-zero; LOG_DEBUG messages can still be displayed if option_debug
-	   is zero, if option_verbose is non-zero (this allows for 'level zero'
-	   LOG_DEBUG messages to be displayed, if the logmask on any channel
-	   allows it)
-	*/
-	if (!option_verbose && !option_debug && (level == __LOG_DEBUG)) {
-		return;
-	}
-
-	/* Ignore anything that never gets logged anywhere */
-	if (!(global_logmask & (1 << level)))
-		return;
-	
-	/* Ignore anything other than the currently debugged file if there is one */
-	if ((level == __LOG_DEBUG) && !ast_strlen_zero(debug_filename) && strcasecmp(debug_filename, file))
-		return;
-
-	/* begin critical section */
-	ast_mutex_lock(&loglock);
-
-	time(&t);
-	localtime_r(&t, &tm);
-	strftime(date, sizeof(date), dateformat, &tm);
-
-	if (logfiles.event_log && level == __LOG_EVENT) {
-		va_start(ap, fmt);
-
-		fprintf(eventlog, "%s asterisk[%d]: ", date, getpid());
-		vfprintf(eventlog, fmt, ap);
-		fflush(eventlog);
-
-		va_end(ap);
-		ast_mutex_unlock(&loglock);
-		return;
-	}
-
-	if (logchannels) {
-		chan = logchannels;
-		while(chan && !chan->disabled) {
-			/* Check syslog channels */
-			if (chan->type == LOGTYPE_SYSLOG && (chan->logmask & (1 << level))) {
-				va_start(ap, fmt);
-				ast_log_vsyslog(level, file, line, function, fmt, ap);
-				va_end(ap);
-			/* Console channels */
-			} else if ((chan->logmask & (1 << level)) && (chan->type == LOGTYPE_CONSOLE)) {
-				char linestr[128];
-				char tmp1[80], tmp2[80], tmp3[80], tmp4[80];
-
-				if (level != __LOG_VERBOSE) {
-					sprintf(linestr, "%d", line);
-					snprintf(buf, sizeof(buf), option_timestamp ? "[%s] %s[%ld]: %s:%s %s: " : "%s %s[%ld]: %s:%s %s: ",
-						date,
-						term_color(tmp1, levels[level], colors[level], 0, sizeof(tmp1)),
-						(long)GETTID(),
-						term_color(tmp2, file, COLOR_BRWHITE, 0, sizeof(tmp2)),
-						term_color(tmp3, linestr, COLOR_BRWHITE, 0, sizeof(tmp3)),
-						term_color(tmp4, function, COLOR_BRWHITE, 0, sizeof(tmp4)));
-					
-					ast_console_puts(buf);
-					va_start(ap, fmt);
-					vsnprintf(buf, sizeof(buf), fmt, ap);
-					va_end(ap);
-					ast_console_puts(buf);
-				}
-			/* File channels */
-			} else if ((chan->logmask & (1 << level)) && (chan->fileptr)) {
-				int res;
-				snprintf(buf, sizeof(buf), option_timestamp ? "[%s] %s[%ld]: " : "%s %s[%ld] %s: ", date,
-					levels[level], (long)GETTID(), file);
-				res = fprintf(chan->fileptr, buf);
-				if (res <= 0 && buf[0] != '\0') {	/* Error, no characters printed */
-					fprintf(stderr,"**** Asterisk Logging Error: ***********\n");
-					if (errno == ENOMEM || errno == ENOSPC) {
-						fprintf(stderr, "Asterisk logging error: Out of disk space, can't log to log file %s\n", chan->filename);
-					} else
-						fprintf(stderr, "Logger Warning: Unable to write to log file '%s': %s (disabled)\n", chan->filename, strerror(errno));
-					manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: No\r\nReason: %d - %s\r\n", chan->filename, errno, strerror(errno));
-					chan->disabled = 1;	
-				} else {
-					/* No error message, continue printing */
-					va_start(ap, fmt);
-					vsnprintf(buf, sizeof(buf), fmt, ap);
-					va_end(ap);
-					term_strip(buf, buf, sizeof(buf));
-					fputs(buf, chan->fileptr);
-					fflush(chan->fileptr);
-				}
-			}
-			chan = chan->next;
-		}
-	} else {
+	if (!logchannels)
+	{
 		/* 
 		 * we don't have the logger chain configured yet,
 		 * so just log to stdout 
@@ -799,6 +712,99 @@
 			va_end(ap);
 			fputs(buf, stdout);
 		}
+		return;
+	}
+
+	/* don't display LOG_DEBUG messages unless option_verbose _or_ option_debug
+	   are non-zero; LOG_DEBUG messages can still be displayed if option_debug
+	   is zero, if option_verbose is non-zero (this allows for 'level zero'
+	   LOG_DEBUG messages to be displayed, if the logmask on any channel
+	   allows it)
+	*/
+	if (!option_verbose && !option_debug && (level == __LOG_DEBUG)) {
+		return;
+	}
+
+	/* Ignore anything that never gets logged anywhere */
+	if (!(global_logmask & (1 << level)))
+		return;
+	
+	/* Ignore anything other than the currently debugged file if there is one */
+	if ((level == __LOG_DEBUG) && !ast_strlen_zero(debug_filename) && strcasecmp(debug_filename, file))
+		return;
+
+	/* begin critical section */
+	ast_mutex_lock(&loglock);
+
+	time(&t);
+	localtime_r(&t, &tm);
+	strftime(date, sizeof(date), dateformat, &tm);
+
+	if (logfiles.event_log && level == __LOG_EVENT) {
+		va_start(ap, fmt);
+
+		fprintf(eventlog, "%s asterisk[%d]: ", date, getpid());
+		vfprintf(eventlog, fmt, ap);
+		fflush(eventlog);
+
+		va_end(ap);
+		ast_mutex_unlock(&loglock);
+		return;
+	}
+
+	chan = logchannels;
+	while(chan && !chan->disabled) {
+		/* Check syslog channels */
+		if (chan->type == LOGTYPE_SYSLOG && (chan->logmask & (1 << level))) {
+			va_start(ap, fmt);
+			ast_log_vsyslog(level, file, line, function, fmt, ap);
+			va_end(ap);
+		/* Console channels */
+		} else if ((chan->logmask & (1 << level)) && (chan->type == LOGTYPE_CONSOLE)) {
+			char linestr[128];
+			char tmp1[80], tmp2[80], tmp3[80], tmp4[80];
+
+			if (level != __LOG_VERBOSE) {
+				sprintf(linestr, "%d", line);
+				snprintf(buf, sizeof(buf), option_timestamp ? "[%s] %s[%ld]: %s:%s %s: " : "%s %s[%ld]: %s:%s %s: ",
+					date,
+					term_color(tmp1, levels[level], colors[level], 0, sizeof(tmp1)),
+					(long)GETTID(),
+					term_color(tmp2, file, COLOR_BRWHITE, 0, sizeof(tmp2)),
+					term_color(tmp3, linestr, COLOR_BRWHITE, 0, sizeof(tmp3)),
+					term_color(tmp4, function, COLOR_BRWHITE, 0, sizeof(tmp4)));
+				
+				ast_console_puts(buf);
+				va_start(ap, fmt);
+				vsnprintf(buf, sizeof(buf), fmt, ap);
+				va_end(ap);
+				ast_console_puts(buf);
+			}
+		/* File channels */
+		} else if ((chan->logmask & (1 << level)) && (chan->fileptr)) {
+			int res;
+			snprintf(buf, sizeof(buf), option_timestamp ? "[%s] %s[%ld]: " : "%s %s[%ld] %s: ", date,
+				levels[level], (long)GETTID(), file);
+			res = fprintf(chan->fileptr, buf);
+			if (res <= 0 && buf[0] != '\0') {	/* Error, no characters printed */
+				fprintf(stderr,"**** Asterisk Logging Error: ***********\n");
+				if (errno == ENOMEM || errno == ENOSPC) {
+					fprintf(stderr, "Asterisk logging error: Out of disk space, can't log to log file %s\n", chan->filename);
+				} else
+					fprintf(stderr, "Logger Warning: Unable to write to log file '%s': %s (disabled)\n", chan->filename, strerror(errno));
+				manager_event(EVENT_FLAG_SYSTEM, "LogChannel", "Channel: %s\r\nEnabled: No\r\nReason: %d - %s\r\n", chan->filename, errno, strerror(errno));
+				chan->disabled = 1;	
+			} else {
+				/* No error message, continue printing */
+				va_start(ap, fmt);
+				vsnprintf(buf, sizeof(buf), fmt, ap);
+				va_end(ap);
+				term_strip(buf, buf, sizeof(buf));
+				fputs(buf, chan->fileptr);
+				fflush(chan->fileptr);
+			}
+		}
+		chan = chan->next;
 	}
 
 	ast_mutex_unlock(&loglock);



More information about the svn-commits mailing list