From bd46061a10c9ba9fbc3b0134d4b8ba126852eb6a Mon Sep 17 00:00:00 2001 From: Chris Rienzo Date: Sat, 16 May 2020 02:40:51 +0000 Subject: [PATCH] [test] Disable logs when loading and shutting down FS core --- src/include/switch_types.h | 6 ++++-- src/include/test/switch_test.h | 19 ++++++++++++++++--- src/switch_core.c | 9 +++++++-- src/switch_log.c | 9 +++++++-- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 4cfeb4231d..24f278f041 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -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; diff --git a/src/include/test/switch_test.h b/src/include/test/switch_test.h index d343ead1b2..561bf7a4fb 100644 --- a/src/include/test/switch_test.h +++ b/src/include/test/switch_test.h @@ -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); \ } \ } \ diff --git a/src/switch_core.c b/src/switch_core.c index e7d478d2b8..62e10d9e35 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -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; } diff --git a/src/switch_log.c b/src/switch_log.c index 59452a84b6..ad74862f6d 100644 --- a/src/switch_log.c +++ b/src/switch_log.c @@ -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;