]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[test] Disable logs when loading and shutting down FS core
authorChris Rienzo <chris@signalwire.com>
Sat, 16 May 2020 02:40:51 +0000 (02:40 +0000)
committerAndrey Volk <andywolk@gmail.com>
Mon, 18 May 2020 17:20:06 +0000 (21:20 +0400)
src/include/switch_types.h
src/include/test/switch_test.h
src/switch_core.c
src/switch_log.c

index 4cfeb4231daa54fcd2b0dfda241c0e6b7ea1a356..24f278f04104004e3115ee41b21cfe3d1046f478 100644 (file)
@@ -389,7 +389,8 @@ typedef enum {
        SCF_CPF_SOFT_LOOKUP = (1 << 26),
        SCF_EVENT_CHANNEL_ENABLE_HIERARCHY_DELIVERY = (1 << 27),
        SCF_EVENT_CHANNEL_HIERARCHY_DELIVERY_ONCE = (1 << 28),
-       SCF_EVENT_CHANNEL_LOG_UNDELIVERABLE_JSON = (1 << 29)
+       SCF_EVENT_CHANNEL_LOG_UNDELIVERABLE_JSON = (1 << 29),
+       SCF_LOG_DISABLE = (1 << 30)
 } switch_core_flag_enum_t;
 typedef uint32_t switch_core_flag_t;
 
@@ -1293,8 +1294,9 @@ typedef enum {
        SWITCH_LOG_CRIT = 2,
        SWITCH_LOG_ALERT = 1,
        SWITCH_LOG_CONSOLE = 0,
+       SWITCH_LOG_DISABLE = -1,
        SWITCH_LOG_INVALID = 64,
-       SWITCH_LOG_UNINIT = 1000,
+       SWITCH_LOG_UNINIT = 1000
 } switch_log_level_t;
 
 
index d343ead1b26b3b24933c2b39168ecbd60026921e..561bf7a4fb6d03f62f9f6d9e7e463ff64cc24837 100644 (file)
@@ -290,7 +290,7 @@ static switch_status_t fst_init_core_and_modload(const char *confdir, const char
                switch_memory_pool_t *fst_pool = NULL; \
                int fst_timer_started = 0; \
                fst_getenv_default("FST_SUPPRESS_UNUSED_STATIC_WARNING", NULL, SWITCH_FALSE); \
-               if (fst_init_core_and_modload(confdir, confdir, 0, flags) == SWITCH_STATUS_SUCCESS) { \
+               if (fst_init_core_and_modload(confdir, confdir, 0, flags | SCF_LOG_DISABLE) == SWITCH_STATUS_SUCCESS) { \
                        fst_core = 2; \
                } else { \
                        fprintf(stderr, "Failed to load FS core\n"); \
@@ -327,7 +327,7 @@ static switch_status_t fst_init_core_and_modload(const char *confdir, const char
                switch_memory_pool_t *fst_pool = NULL; \
                int fst_timer_started = 0; \
                fst_getenv_default("FST_SUPPRESS_UNUSED_STATIC_WARNING", NULL, SWITCH_FALSE); \
-               if (fst_init_core_and_modload(confdir, NULL, 1, 0) == SWITCH_STATUS_SUCCESS) { /* minimal load */ \
+               if (fst_init_core_and_modload(confdir, NULL, 1, 0 | SCF_LOG_DISABLE) == SWITCH_STATUS_SUCCESS) { /* minimal load */ \
                        fst_core = 1; \
                } else { \
                        fprintf(stderr, "Failed to load FS core\n"); \
@@ -446,6 +446,8 @@ static switch_status_t fst_init_core_and_modload(const char *confdir, const char
 #define FST_TEST_BEGIN(name) \
        FCT_TEST_BGN(name) \
                if (fst_core) { \
+                       switch_log_level_t level = SWITCH_LOG_DEBUG; \
+                       switch_core_session_ctl(SCSC_LOGLEVEL, &level); \
                        fst_requires(fst_pool != NULL); \
                        if (fst_core > 1) { \
                                fst_requires(fst_timer_started); \
@@ -456,7 +458,12 @@ static switch_status_t fst_init_core_and_modload(const char *confdir, const char
                        fst_requires_module(fst_test_module); \
                }
 
-#define FST_TEST_END FCT_TEST_END
+#define FST_TEST_END \
+       if (fst_core) { \
+               switch_log_level_t level = SWITCH_LOG_DISABLE; \
+               switch_core_session_ctl(SCSC_LOGLEVEL, &level); \
+       } \
+       FCT_TEST_END
 
 
 /**
@@ -483,6 +490,8 @@ static switch_status_t fst_init_core_and_modload(const char *confdir, const char
        FCT_TEST_BGN(name) \
        { \
                if (fst_core) { \
+                       switch_log_level_t level = SWITCH_LOG_DEBUG; \
+                       switch_core_session_ctl(SCSC_LOGLEVEL, &level); \
                        fst_requires(fst_pool != NULL); \
                        if (fst_core > 1) { \
                                fst_requires(fst_timer_started); \
@@ -540,6 +549,10 @@ static switch_status_t fst_init_core_and_modload(const char *confdir, const char
                                fst_session_pool = NULL; \
                        } \
                        switch_core_session_rwunlock(fst_session); \
+                       if (fst_core) { \
+                               switch_log_level_t level = SWITCH_LOG_DISABLE; \
+                               switch_core_session_ctl(SCSC_LOGLEVEL, &level); \
+                       } \
                        switch_sleep(1000000); \
                } \
        } \
index e7d478d2b8e0fc011dc4fa9d3fe7fac4cb0f5a84..62e10d9e3531c857f80a1db441a5e239e4d41f0a 100644 (file)
@@ -1859,7 +1859,12 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
        switch_set_flag((&runtime), SCF_THREADED_SYSTEM_EXEC);
 #endif
        switch_set_flag((&runtime), SCF_NO_NEW_SESSIONS);
-       runtime.hard_log_level = SWITCH_LOG_DEBUG;
+       if (flags & SCF_LOG_DISABLE) {
+               runtime.hard_log_level = SWITCH_LOG_DISABLE;
+               flags &= ~SCF_LOG_DISABLE;
+       } else {
+               runtime.hard_log_level = SWITCH_LOG_DEBUG;
+       }
        runtime.mailer_app = "sendmail";
        runtime.mailer_app_args = "-t";
        runtime.max_dtmf_duration = SWITCH_MAX_DTMF_DURATION;
@@ -2898,7 +2903,7 @@ SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, void *
                newintval = runtime.running;
                break;
        case SCSC_LOGLEVEL:
-               if (oldintval > -1) {
+               if (oldintval >= SWITCH_LOG_DISABLE) {
                        runtime.hard_log_level = oldintval;
                }
 
index 59452a84b6e3899cf8067cdf1f7f002b49b57666..ad74862f6d33d93a57a6bbbdc965d98140ce673c 100644 (file)
@@ -34,6 +34,7 @@
 #include "private/switch_core_pvt.h"
 
 static const char *LEVELS[] = {
+       "DISABLE",
        "CONSOLE",
        "ALERT",
        "CRIT",
@@ -301,7 +302,7 @@ SWITCH_DECLARE(const char *) switch_log_level2str(switch_log_level_t level)
        if (level > SWITCH_LOG_DEBUG) {
                level = SWITCH_LOG_DEBUG;
        }
-       return LEVELS[level];
+       return LEVELS[level + 1];
 }
 
 static int switch_log_to_mask(switch_log_level_t level)
@@ -382,7 +383,7 @@ SWITCH_DECLARE(switch_log_level_t) switch_log_str2level(const char *str)
                }
 
                if (!strcasecmp(LEVELS[x], str)) {
-                       level = (switch_log_level_t) x;
+                       level = (switch_log_level_t)(x - 1);
                        break;
                }
        }
@@ -524,6 +525,10 @@ SWITCH_DECLARE(void) switch_log_vprintf(switch_text_channel_t channel, const cha
        switch_log_level_t limit_level = runtime.hard_log_level;
        switch_log_level_t special_level = SWITCH_LOG_UNINIT;
 
+       if (limit_level == SWITCH_LOG_DISABLE) {
+               return;
+       }
+
        if (channel == SWITCH_CHANNEL_ID_SESSION && userdata) {
                switch_core_session_t *session = (switch_core_session_t *) userdata;
                special_level = session->loglevel;