]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add fsctl loglevel [<level>] fsctl command
authorAnthony Minessale <anthony.minessale@gmail.com>
Wed, 3 Oct 2007 23:43:01 +0000 (23:43 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Wed, 3 Oct 2007 23:43:01 +0000 (23:43 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5790 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/private/switch_core_pvt.h
src/include/switch_core.h
src/include/switch_types.h
src/mod/applications/mod_commands/mod_commands.c
src/switch.c
src/switch_console.c
src/switch_core.c
src/switch_log.c

index 3992eb9e24a6c0cae6d1eb8c7de67c97f11864cd..12c315847eb027c154d17876b652ad9f211db61b 100644 (file)
@@ -156,6 +156,7 @@ struct switch_runtime {
        switch_mutex_t *throttle_mutex;
        uint32_t sps_total;
        int32_t sps;
+       uint32_t hard_log_level;
 };
 
 extern struct switch_runtime runtime;
index 819f74e8c92ea7a25a7f2e0ddda751b5a87d8ebb..29aed6c49fb9e47e53f6e3fdace2f1d495f4cbe9 100644 (file)
@@ -1443,7 +1443,7 @@ SWITCH_DECLARE(switch_time_t) switch_core_uptime(void);
   \param val the command arguement (if needed)
   \return 0 on success nonzero on error
 */
-SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, uint32_t * val);
+SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, int32_t * val);
 
 /*!
   \brief Get the output console
index 9eb8fe3c821f7f454560f1494453a7a531c00407..b48ec2ed0dd027524e779f739a48e8d501f103b7 100644 (file)
@@ -1007,7 +1007,8 @@ typedef enum {
        SCSC_PAUSE_INBOUND,
        SCSC_HUPALL,
        SCSC_SHUTDOWN,
-       SCSC_CHECK_RUNNING
+       SCSC_CHECK_RUNNING,
+       SCSC_LOGLEVEL
 } switch_session_ctl_t;
 
 typedef struct apr_pool_t switch_memory_pool_t;
index 1baaf97ba095abef339b2887e574f673be1f00ad..ba1e1ffc79b2b2ce4cd791b46e14872c23251566 100644 (file)
@@ -94,7 +94,7 @@ SWITCH_STANDARD_API(ctl_function)
 {
        int argc;
        char *mydata, *argv[5];
-       uint32_t arg = 0;
+       int32_t arg = 0;
 
        if (switch_strlen_zero(cmd)) {
                stream->write_function(stream, "USAGE: %s\n", CTL_SYNTAX);
@@ -116,6 +116,18 @@ SWITCH_STANDARD_API(ctl_function)
                } else if (!strcasecmp(argv[0], "shutdown")) {
                        arg = 0;
                        switch_core_session_ctl(SCSC_SHUTDOWN, &arg);
+               } else if (!strcasecmp(argv[0], "loglevel")) {
+                       if (argc > 1) {
+                               if (*argv[1] > 47 && *argv[1] < 58) {
+                                       arg = atoi(argv[1]);
+                               } else {
+                                       arg = switch_log_str2level(argv[1]);
+                               }
+                       } else {
+                               arg = -1;
+                       }
+                       switch_core_session_ctl(SCSC_LOGLEVEL, &arg);
+                       stream->write_function(stream, "log level %s [%d]\n", switch_log_level2str(arg), arg);
                } else {
                        stream->write_function(stream, "INVALID COMMAND\nUSAGE: fsctl [hupall|pause|resume|shutdown]\n");
                        goto end;
index e27c20cebc1c8e339d3f7970a4ca2bf64dcd114b..e312cdb786aa2f3c2b8d07fe8cba7221d6f63293 100644 (file)
@@ -68,7 +68,7 @@ static HANDLE shutdown_event;
  */
 static void handle_SIGHUP(int sig)
 {
-       uint32_t arg = 0;
+       int32_t arg = 0;
        if (sig);
        /* send shutdown signal to the freeswitch core */
        switch_core_session_ctl(SCSC_SHUTDOWN, &arg);
index fce2e763ad0594779b4396eda5099a308cf2e855..f69d42cf87d3acf0f6569f06dae66112e87470a3 100644 (file)
@@ -204,7 +204,7 @@ static void *SWITCH_THREAD_FUNC console_thread(switch_thread_t *thread, void *ob
        switch_memory_pool_t *pool = (switch_memory_pool_t *) obj;
 
        while (running) {
-               uint32_t arg;
+               int32_t arg;
 
                switch_core_session_ctl(SCSC_CHECK_RUNNING, &arg);
                if (!arg) {
@@ -270,7 +270,7 @@ SWITCH_DECLARE(void) switch_console_loop(void)
        switch_thread_create(&thread, thd_attr, console_thread, pool, pool);
        
        while (running) {
-               uint32_t arg = 0;
+               int32_t arg = 0;
                switch_core_session_ctl(SCSC_CHECK_RUNNING, &arg);
                if (!arg) {
                        break;
index 9802ce2375540380af00a114ce60a5c93095abe6..7962cebe861ced391b67873416aea25815e79cf2 100644 (file)
@@ -623,7 +623,7 @@ SWITCH_DECLARE(switch_time_t) switch_core_uptime(void)
        return switch_time_now() - runtime.initiated;
 }
 
-SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, uint32_t * val)
+SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, int32_t * val)
 {
        if (switch_test_flag((&runtime), SCF_SHUTTING_DOWN)) {
                return -1;
@@ -646,6 +646,18 @@ SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, uint32
        case SCSC_CHECK_RUNNING:
                *val = runtime.running;
                break;
+       case SCSC_LOGLEVEL:
+               if (*val > -1) {
+                       printf("WTF %d\n", *val);
+                       runtime.hard_log_level = *val;
+               }
+
+               if (runtime.hard_log_level > SWITCH_LOG_CONSOLE) {
+                       printf("WTF %d\n", *val);
+                       runtime.hard_log_level = SWITCH_LOG_CONSOLE;
+               }
+               *val = runtime.hard_log_level;
+               break;
        }
 
        return 0;
index 5e59c99e7d6696c2f628d861816ec526f4623edd..3fc9a09ef65e2bb3bd6f9bd67a4e7e1bb7b17aa0 100644 (file)
@@ -30,7 +30,8 @@
  *
  */
 #include <switch.h>
-
+#include "private/switch_core_pvt.h"
+struct switch_runtime runtime;
 
 static const char *LEVELS[] = {
        "EMERG",
@@ -166,6 +167,10 @@ SWITCH_DECLARE(void) switch_log_printf(switch_text_channel_t channel, const char
        uint32_t len;
        const char *extra_fmt = "%s [%s] %s:%d %s()%c%s";
 
+       if (level < runtime.hard_log_level) {
+               return;
+       }
+
        va_start(ap, fmt);
 
        handle = switch_core_data_channel(channel);