[Freeswitch-svn] [commit] r6604 - in freeswitch/trunk: conf/autoload_configs src src/include src/mod/applications/mod_commands src/mod/applications/mod_dptools src/mod/event_handlers/mod_event_socket src/mod/languages/mod_spidermonkey src/mod/loggers/mod_console

Freeswitch SVN mikej at freeswitch.org
Mon Dec 10 14:16:51 EST 2007


Author: mikej
Date: Mon Dec 10 14:16:50 2007
New Revision: 6604

Modified:
   freeswitch/trunk/conf/autoload_configs/console.conf.xml
   freeswitch/trunk/conf/autoload_configs/logfile.conf.xml
   freeswitch/trunk/conf/autoload_configs/switch.conf.xml
   freeswitch/trunk/src/include/switch_types.h
   freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
   freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
   freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
   freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
   freeswitch/trunk/src/mod/loggers/mod_console/mod_console.c
   freeswitch/trunk/src/switch_core.c
   freeswitch/trunk/src/switch_cpp.cpp
   freeswitch/trunk/src/switch_log.c

Log:
handle invalid log level strings. (FSCORE-69)

Modified: freeswitch/trunk/conf/autoload_configs/console.conf.xml
==============================================================================
--- freeswitch/trunk/conf/autoload_configs/console.conf.xml	(original)
+++ freeswitch/trunk/conf/autoload_configs/console.conf.xml	Mon Dec 10 14:16:50 2007
@@ -4,9 +4,9 @@
   <mappings>
     <!-- 
 	 name can be a file name, function name or 'all' 
-	 value is one or more of debug,info,notice,warning,error,crit,alert,all
+	 value is one or more of debug,info,notice,warning,err,crit,alert,all
     -->
-    <map name="all" value="debug,info,notice,warning,error,crit,alert"/>
+    <map name="all" value="debug,info,notice,warning,err,crit,alert"/>
   </mappings>
   <settings>
     <!-- comment or set to false for no color logging -->

Modified: freeswitch/trunk/conf/autoload_configs/logfile.conf.xml
==============================================================================
--- freeswitch/trunk/conf/autoload_configs/logfile.conf.xml	(original)
+++ freeswitch/trunk/conf/autoload_configs/logfile.conf.xml	Mon Dec 10 14:16:50 2007
@@ -14,9 +14,9 @@
       <mappings>
 	<!-- 
 	     name can be a file name, function name or 'all' 
-	     value is one or more of debug,info,notice,warning,error,crit,alert,all
+	     value is one or more of debug,info,notice,warning,err,crit,alert,all
 	-->
-	<map name="all" value="debug,info,notice,warning,error,crit,alert"/>
+	<map name="all" value="debug,info,notice,warning,err,crit,alert"/>
       </mappings>
     </profile>
   </profiles>

Modified: freeswitch/trunk/conf/autoload_configs/switch.conf.xml
==============================================================================
--- freeswitch/trunk/conf/autoload_configs/switch.conf.xml	(original)
+++ freeswitch/trunk/conf/autoload_configs/switch.conf.xml	Mon Dec 10 14:16:50 2007
@@ -4,7 +4,7 @@
     <param name="max-sessions" value="1000"/>
     <!--Most channels to create per second -->
     <param name="sessions-per-second" value="30"/>
-    <!--Default Global Log Level -->
+    <!-- Default Global Log Level - value is one of debug,info,notice,warning,err,crit,alert -->
     <param name="loglevel" value="debug"/>
     <!--Try to catch any crashes that can be recoverable (in the context of a call)-->
     <param name="crash-protection" value="false"/>

Modified: freeswitch/trunk/src/include/switch_types.h
==============================================================================
--- freeswitch/trunk/src/include/switch_types.h	(original)
+++ freeswitch/trunk/src/include/switch_types.h	Mon Dec 10 14:16:50 2007
@@ -516,7 +516,8 @@
 	SWITCH_LOG_ERROR = 3,
 	SWITCH_LOG_CRIT = 2,
 	SWITCH_LOG_ALERT = 1,
-	SWITCH_LOG_CONSOLE = 0
+	SWITCH_LOG_CONSOLE = 0,
+	SWITCH_LOG_INVALID = 64
 } switch_log_level_t;
 
 

Modified: freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c	Mon Dec 10 14:16:50 2007
@@ -565,8 +565,13 @@
 			} else {
 				arg = -1;
 			}
-			switch_core_session_ctl(SCSC_LOGLEVEL, &arg);
-			stream->write_function(stream, "+OK log level: %s [%d]\n", switch_log_level2str(arg), arg);
+
+			if (arg == -1 || arg == SWITCH_LOG_INVALID) {
+				stream->write_function(stream, "-ERR syntax error, log level not set!\n");
+			} else {
+				switch_core_session_ctl(SCSC_LOGLEVEL, &arg);
+				stream->write_function(stream, "+OK log level: %s [%d]\n", switch_log_level2str(arg), arg);
+			}
 		} else if (!strcasecmp(argv[0], "last_sps")) {
 			switch_core_session_ctl(SCSC_LAST_SPS, &arg);
 			stream->write_function(stream, "+OK last sessions per second: %d\n", arg);

Modified: freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c	Mon Dec 10 14:16:50 2007
@@ -635,6 +635,9 @@
 		} else {
 			log_str = level;
 		}
+		if (ltype == SWITCH_LOG_INVALID) {
+			ltype = SWITCH_LOG_DEBUG;
+		}
 
 		switch_log_printf(SWITCH_CHANNEL_LOG, ltype, "%s\n", log_str);
 		switch_safe_free(level);

Modified: freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
==============================================================================
--- freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c	(original)
+++ freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c	Mon Dec 10 14:16:50 2007
@@ -811,6 +811,7 @@
 	} else if (!strncasecmp(cmd, "log", 3)) {
 
 		char *level_s;
+		switch_log_level_t ltype = SWITCH_LOG_DEBUG;
 
 		//pull off the first newline/carriage return
 		strip_cr(cmd);
@@ -824,11 +825,12 @@
 			level_s++;
 		}
 		//see if we lined up on an argument or not
-		if (switch_strlen_zero(level_s)) {
-			level_s = "debug";
+		if (!switch_strlen_zero(level_s)) {
+			ltype = switch_log_str2level(level_s);
 		}
 
-		if ((listener->level = switch_log_str2level(level_s))) {
+		if (ltype && ltype != SWITCH_LOG_INVALID) {
+			listener->level = ltype;
 			switch_set_flag(listener, LFLAG_LOG);
 			snprintf(reply, reply_len, "+OK log level %s [%d]", level_s, listener->level);
 		} else {

Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	(original)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	Mon Dec 10 14:16:50 2007
@@ -3002,6 +3002,9 @@
 	if (argc > 1) {
 		if ((level_str = JS_GetStringBytes(JS_ValueToString(cx, argv[0])))) {
 			level = switch_log_str2level(level_str);
+			if (level == SWITCH_LOG_INVALID) {
+				level = SWITCH_LOG_DEBUG;
+			}
 		}
 
 		if ((msg = JS_GetStringBytes(JS_ValueToString(cx, argv[1])))) {

Modified: freeswitch/trunk/src/mod/loggers/mod_console/mod_console.c
==============================================================================
--- freeswitch/trunk/src/mod/loggers/mod_console/mod_console.c	(original)
+++ freeswitch/trunk/src/mod/loggers/mod_console/mod_console.c	Mon Dec 10 14:16:50 2007
@@ -76,10 +76,10 @@
 		uint32_t l = switch_log_str2level(val);
 		uint32_t i;
 
-		assert(l < 10);
-		
-		for (i = 0; i <= l; i++) {
-			m |= (1 << i);
+		if (l < 10) {
+			for (i = 0; i <= l; i++) {
+				m |= (1 << i);
+			}
 		}
 	} else {
 		m = switch_log_str2mask(val);
@@ -227,8 +227,12 @@
 				level = switch_log_str2level(argv[1]);
 			}
 
-			hard_log_level = level;
-			stream->write_function(stream,  "+OK console log level set to %s\n", switch_log_level2str(hard_log_level));
+			if (level == SWITCH_LOG_INVALID) {
+				stream->write_function(stream, "-ERR syntax error, console log level not set!\n");
+			} else {
+				hard_log_level = level;
+				stream->write_function(stream,  "+OK console log level set to %s\n", switch_log_level2str(hard_log_level));
+			}
 			goto end;
 		} else if (!strcasecmp(argv[0], "colorize")) {
 			COLORIZE = switch_true(argv[1]);

Modified: freeswitch/trunk/src/switch_core.c
==============================================================================
--- freeswitch/trunk/src/switch_core.c	(original)
+++ freeswitch/trunk/src/switch_core.c	Mon Dec 10 14:16:50 2007
@@ -706,7 +706,9 @@
                         level = switch_log_str2level(val);
                     }
 
-                    switch_core_session_ctl(SCSC_LOGLEVEL, &level);
+					if (level != SWITCH_LOG_INVALID) {
+	                    switch_core_session_ctl(SCSC_LOGLEVEL, &level);
+					}
 					
 				} else if (!strcasecmp(var, "mailer-app")) {
 					runtime.mailer_app = switch_core_strdup(runtime.memory_pool, val);

Modified: freeswitch/trunk/src/switch_cpp.cpp
==============================================================================
--- freeswitch/trunk/src/switch_cpp.cpp	(original)
+++ freeswitch/trunk/src/switch_cpp.cpp	Mon Dec 10 14:16:50 2007
@@ -485,6 +485,9 @@
     switch_log_level_t level = SWITCH_LOG_DEBUG;
     if (level_str) {
         level = switch_log_str2level(level_str);
+		if (level == SWITCH_LOG_INVALID) {
+			level = SWITCH_LOG_DEBUG;
+		}
     }
     switch_log_printf(SWITCH_CHANNEL_LOG, level, msg);
 	fflush(stdout); // TEMP ONLY!! SHOULD NOT BE CHECKED IN!!

Modified: freeswitch/trunk/src/switch_log.c
==============================================================================
--- freeswitch/trunk/src/switch_log.c	(original)
+++ freeswitch/trunk/src/switch_log.c	Mon Dec 10 14:16:50 2007
@@ -75,6 +75,7 @@
 	char *argv[10] = { 0 };
 	uint32_t mask = 0;
 	char *p = strdup(str);
+	switch_log_level_t level;
 
 	assert(p);
 
@@ -84,7 +85,10 @@
 				mask = 0xFF;
 				break;
 			} else {
-				mask |= (1 << switch_log_str2level(argv[x]));
+				level = switch_log_str2level(argv[x]);
+				if (level != SWITCH_LOG_INVALID) {
+					mask |= (1 << level);
+				}
 			}
 		}
 	}
@@ -99,7 +103,7 @@
 SWITCH_DECLARE(switch_log_level_t) switch_log_str2level(const char *str)
 {
 	int x = 0;
-	switch_log_level_t level = SWITCH_LOG_DEBUG;
+	switch_log_level_t level = SWITCH_LOG_INVALID;
 
 	for (x = 0;; x++) {
 		if (!LEVELS[x]) {



More information about the Freeswitch-svn mailing list