]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[mod_verto] add debug controls for verto
authorAnthony Minessale <anthm@signalwire.com>
Wed, 1 Apr 2020 00:31:23 +0000 (00:31 +0000)
committerAndrey Volk <andywolk@gmail.com>
Sat, 23 Oct 2021 19:00:20 +0000 (22:00 +0300)
src/mod/endpoints/mod_verto/mod_verto.c
src/mod/endpoints/mod_verto/mod_verto.h

index 4420f86a21e6d52348ebdc773752df0824d3def1..b92693870ac7e190abc36de85b0045464816f103 100644 (file)
@@ -293,7 +293,7 @@ static uint32_t jsock_unsub_head(jsock_t *jsock, jsock_sub_node_head_t *head)
                        }
 
                        if (thisnp->jsock->profile->debug || verto_globals.debug) {
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "UNSUBBING %s [%s]\n", thisnp->jsock->name, thisnp->head->event_channel);
+                               switch_log_printf(SWITCH_CHANNEL_LOG, verto_globals.debug_level, "UNSUBBING %s [%s]\n", thisnp->jsock->name, thisnp->head->event_channel);
                        }
 
                        thisnp->jsock = NULL;
@@ -603,7 +603,7 @@ static switch_ssize_t ws_write_json(jsock_t *jsock, cJSON **json, switch_bool_t
        if ((json_text = cJSON_PrintUnformatted(*json))) {
                if (jsock->profile->debug || verto_globals.debug) {
                        char *log_text = cJSON_Print(*json);
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "WRITE %s [%s]\n", jsock->name, log_text);
+                       switch_log_printf(SWITCH_CHANNEL_LOG, verto_globals.debug_level, "WRITE %s [%s]\n", jsock->name, log_text);
                        free(log_text);
                }
                switch_mutex_lock(jsock->write_mutex);
@@ -1429,7 +1429,7 @@ static switch_status_t process_input(jsock_t *jsock, uint8_t *data, switch_ssize
 
                if (jsock->profile->debug || verto_globals.debug) {
                        char *log_text = cJSON_Print(json);
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "READ %s [%s]\n", jsock->name, log_text);
+                       switch_log_printf(SWITCH_CHANNEL_LOG, verto_globals.debug_level, "READ %s [%s]\n", jsock->name, log_text);
                        free(log_text);
                }
 
@@ -4218,7 +4218,7 @@ static switch_bool_t verto__broadcast_func(const char *method, cJSON *params, js
                                //r = SWITCH_TRUE;
                                //cJSON_AddItemToObject(*response, "message", cJSON_CreateString("MCAST Data Sent"));
                                if (verto_globals.debug > 0) {
-                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "MCAST Data Sent: %s\n",json_text);
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, verto_globals.debug_level, "MCAST Data Sent: %s\n",json_text);
                                }
                        }
                        free(json_text);
@@ -5301,6 +5301,7 @@ SWITCH_STANDARD_API(verto_function)
                "--------------------------------------------------------------------------------\n"
                "verto [status|xmlstatus]\n"
                "verto help\n"
+               "verto debug [0-10]\n"
                "--------------------------------------------------------------------------------\n";
 
        if (zstr(cmd)) {
@@ -5325,6 +5326,22 @@ SWITCH_STANDARD_API(verto_function)
                func = cmd_status;
        } else if (!strcasecmp(argv[0], "xmlstatus")) {
                func = cmd_xml_status;
+       } else if (!strcasecmp(argv[0], "debug")) {
+               if (argv[1]) {
+                       int tmp = atoi(argv[1]);
+
+                       if (tmp >= 0 && tmp <= 10) {
+                               verto_globals.debug = tmp;
+                       }
+               }
+               stream->write_function(stream, "Debug Level: %d\n", verto_globals.debug);
+               goto done;
+       } else if (!strcasecmp(argv[0], "debug-level")) {
+               if (argv[1]) {
+                       verto_globals.debug_level = switch_log_str2level(argv[1]);
+               }
+               stream->write_function(stream, "Debug Level: %s\n", switch_log_level2str(verto_globals.debug_level));
+               goto done;
        }
 
        if (func) {
@@ -5740,7 +5757,7 @@ void verto_broadcast(const char *event_channel, cJSON *json, const char *key, sw
        if (verto_globals.debug > 9) {
                char *json_text;
                if ((json_text = cJSON_Print(json))) {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "EVENT BROADCAST %s %s\n", event_channel, json_text);
+                       switch_log_printf(SWITCH_CHANNEL_LOG, verto_globals.debug_level, "EVENT BROADCAST %s %s\n", event_channel, json_text);
                        free(json_text);
                }
        }
@@ -6338,7 +6355,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_verto_load)
 #endif
        verto_globals.enable_presence = SWITCH_TRUE;
        verto_globals.enable_fs_events = SWITCH_FALSE;
-
+       verto_globals.debug_level = SWITCH_LOG_INFO;
+       
        switch_mutex_init(&verto_globals.mutex, SWITCH_MUTEX_NESTED, verto_globals.pool);
 
        switch_mutex_init(&verto_globals.method_mutex, SWITCH_MUTEX_NESTED, verto_globals.pool);
@@ -6391,6 +6409,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_verto_load)
        SWITCH_ADD_API(api_interface, "verto", "Verto API", verto_function, "syntax");
        SWITCH_ADD_API(api_interface, "verto_contact", "Generate a verto endpoint dialstring", verto_contact_function, "user@domain");
        switch_console_set_complete("add verto help");
+       switch_console_set_complete("add verto debug");
+       switch_console_set_complete("add verto debug-level");
        switch_console_set_complete("add verto status");
        switch_console_set_complete("add verto xmlstatus");
 
index c82f813da4dcebc13a596c6b4f6032119f14dc17..bbf0114503401cc6e6fd85e40c3c59a0068c1089 100644 (file)
@@ -326,6 +326,9 @@ struct globals_s {
        uint32_t detach_timeout;
 
        switch_event_channel_id_t event_channel_id;
+
+       switch_log_level_t debug_level;
+
 };