]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
handle invalid log level strings. (FSCORE-69)
authorMichael Jerris <mike@jerris.com>
Mon, 10 Dec 2007 19:16:50 +0000 (19:16 +0000)
committerMichael Jerris <mike@jerris.com>
Mon, 10 Dec 2007 19:16:50 +0000 (19:16 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6604 d0543943-73ff-0310-b7d9-9358b9ac24b2

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

index 6076c5156ed2f2c5d14e192e25de687c3ce502a3..76508cb17e16227ca060bc22052f3afae6fc6d6d 100644 (file)
@@ -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 -->
index 32d59c4ee915b134b247322aee732c57911d5dd2..e666cc946933b5dd402d9a68316635180dae5899 100644 (file)
@@ -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>
index f30ac7cb835164b9e6ed8e30946fcc8c66f44863..7cb3ecfa90f266dd79d037247a97fff169c3e81b 100644 (file)
@@ -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"/>
index 47eef5042594a406917e905cfbfc611515109c99..76067565f24c217339755e79d23335cc127117db 100644 (file)
@@ -516,7 +516,8 @@ typedef enum {
        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;
 
 
index c3d123a7dbf3f38917dabc75fa550f373068e823..685fc53f0e272ea0a2f0fc9c810f85d1e516e52b 100644 (file)
@@ -565,8 +565,13 @@ SWITCH_STANDARD_API(ctl_function)
                        } 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);
index b79218f9c54b706704bcee8da82c3be8c7c38ef4..ed14c4932935374bef1c49d39594cc102928b97a 100644 (file)
@@ -635,6 +635,9 @@ SWITCH_STANDARD_APP(log_function)
                } 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);
index 77743badc28cce266165c509fe4eab96b58fc91f..98ecbb8377fadd5c66d3c47575322b0f938974c7 100644 (file)
@@ -811,6 +811,7 @@ static switch_status_t parse_command(listener_t * listener, switch_event_t *even
        } 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 @@ static switch_status_t parse_command(listener_t * listener, switch_event_t *even
                        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 {
index 00ca044f07798ebb9a17162a9a3cdc78350e0203..f6dd34c89103459141eb574279fdaa1148e9200e 100644 (file)
@@ -3002,6 +3002,9 @@ static JSBool js_log(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, j
        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])))) {
index d0a35fbeb4c307f278aee45f13af49c77b8a791e..c3c59464af5c01fb84e01fbf4bd835e7e033ca02 100644 (file)
@@ -76,10 +76,10 @@ static void add_mapping(char *var, char *val, int cumlative)
                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 @@ SWITCH_STANDARD_API(console_api_function)
                                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]);
index 60535817aad0a2f0ab8f9bb388ca3ce8fc0d8fff..b31740261dabca94df29e6579670237fafc519c7 100644 (file)
@@ -706,7 +706,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
                         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);
index 6bc8335a69e45e9a8dd92c59037b6faf64131949..110518fcc9a969371eb2a855671ffc70dade89c8 100644 (file)
@@ -485,6 +485,9 @@ void console_log(char *level_str, char *msg)
     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!!
index 55c6ca074ecd060e78d842a8d808e4babc569699..2ac0a70d26c047b8b8511604faa24573426af055 100644 (file)
@@ -75,6 +75,7 @@ SWITCH_DECLARE(uint32_t) switch_log_str2mask(const char *str)
        char *argv[10] = { 0 };
        uint32_t mask = 0;
        char *p = strdup(str);
+       switch_log_level_t level;
 
        assert(p);
 
@@ -84,7 +85,10 @@ SWITCH_DECLARE(uint32_t) switch_log_str2mask(const char *str)
                                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(uint32_t) switch_log_str2mask(const char *str)
 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]) {