[test] Disable logs when loading and shutting down FS core

This commit is contained in:
Chris Rienzo 2020-05-16 02:40:51 +00:00 committed by Andrey Volk
parent e1f63ce5b1
commit bd46061a10
4 changed files with 34 additions and 9 deletions

View 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;

View 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); \
} \
} \

View 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;
}

View 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;