diff --git a/src/include/private/switch_core_pvt.h b/src/include/private/switch_core_pvt.h index 3992eb9e24..12c315847e 100644 --- a/src/include/private/switch_core_pvt.h +++ b/src/include/private/switch_core_pvt.h @@ -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; diff --git a/src/include/switch_core.h b/src/include/switch_core.h index 819f74e8c9..29aed6c49f 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -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 diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 9eb8fe3c82..b48ec2ed0d 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -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; diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 1baaf97ba0..ba1e1ffc79 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -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; diff --git a/src/switch.c b/src/switch.c index e27c20cebc..e312cdb786 100644 --- a/src/switch.c +++ b/src/switch.c @@ -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); diff --git a/src/switch_console.c b/src/switch_console.c index fce2e763ad..f69d42cf87 100644 --- a/src/switch_console.c +++ b/src/switch_console.c @@ -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; diff --git a/src/switch_core.c b/src/switch_core.c index 9802ce2375..7962cebe86 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -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; diff --git a/src/switch_log.c b/src/switch_log.c index 5e59c99e7d..3fc9a09ef6 100644 --- a/src/switch_log.c +++ b/src/switch_log.c @@ -30,7 +30,8 @@ * */ #include - +#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);