diff --git a/src/include/switch_log.h b/src/include/switch_log.h index a44aa29a01..603fcc2e1f 100644 --- a/src/include/switch_log.h +++ b/src/include/switch_log.h @@ -64,6 +64,7 @@ SWITCH_BEGIN_EXTERN_C char *userdata; /* To maintain abi, only add new elements to the end of this struct and do not delete any elements */ switch_text_channel_t channel; + switch_log_level_t slevel; } switch_log_node_t; typedef switch_status_t (*switch_log_function_t) (const switch_log_node_t *node, switch_log_level_t level); diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 7bdf230690..f1c5f1b65a 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -1030,7 +1030,8 @@ typedef enum { SWITCH_LOG_CRIT = 2, SWITCH_LOG_ALERT = 1, SWITCH_LOG_CONSOLE = 0, - SWITCH_LOG_INVALID = 64 + SWITCH_LOG_INVALID = 64, + SWITCH_LOG_UNINIT = 1000, } switch_log_level_t; diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 7287d95acc..679f29baaa 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -5472,12 +5472,20 @@ SWITCH_STANDARD_API(escape_function) #define UUID_LOGLEVEL_SYNTAX " " SWITCH_STANDARD_API(uuid_loglevel) { - switch_core_session_t *tsession = NULL; + switch_core_session_t *tsession = NULL, *bsession = NULL; char *uuid = NULL, *text = NULL; + int b = 0; if (!zstr(cmd) && (uuid = strdup(cmd))) { if ((text = strchr(uuid, ' '))) { *text++ = '\0'; + + if (!strncasecmp(text, "-b", 2)) { + b++; + if ((text = strchr(text, ' '))) { + *text++ = '\0'; + } + } } } @@ -5491,6 +5499,12 @@ SWITCH_STANDARD_API(uuid_loglevel) } else if ((tsession = switch_core_session_locate(uuid))) { switch_core_session_set_loglevel(tsession, level); + + if (b && switch_core_session_get_partner(tsession, &bsession) == SWITCH_STATUS_SUCCESS) { + switch_core_session_set_loglevel(bsession, level); + switch_core_session_rwunlock(bsession); + } + stream->write_function(stream, "+OK\n"); switch_core_session_rwunlock(tsession); } else { diff --git a/src/mod/loggers/mod_console/mod_console.c b/src/mod/loggers/mod_console/mod_console.c index 451cca78c3..a55a6bdc6a 100644 --- a/src/mod/loggers/mod_console/mod_console.c +++ b/src/mod/loggers/mod_console/mod_console.c @@ -206,7 +206,7 @@ static switch_status_t switch_console_logger(const switch_log_node_t *node, swit } #endif - if (level > hard_log_level) { + if (level > hard_log_level && (node->slevel == SWITCH_LOG_UNINIT || level > node->slevel)) { return SWITCH_STATUS_SUCCESS; } diff --git a/src/switch_core_session.c b/src/switch_core_session.c index ab52bb89dd..a65688753a 100644 --- a/src/switch_core_session.c +++ b/src/switch_core_session.c @@ -531,6 +531,11 @@ SWITCH_DECLARE(switch_call_cause_t) switch_core_session_outgoing_channel(switch_ switch_assert(peer_channel); + if (channel && switch_true(switch_channel_get_variable(channel, "session_copy_loglevel"))) { + (*new_session)->loglevel = session->loglevel; + } + + if ((use_uuid = switch_event_get_header(var_event, "origination_uuid"))) { use_uuid = switch_core_session_strdup(*new_session, use_uuid); if (switch_core_session_set_uuid(*new_session, use_uuid) == SWITCH_STATUS_SUCCESS) { diff --git a/src/switch_log.c b/src/switch_log.c index 9799a3698f..c8bdad3917 100644 --- a/src/switch_log.c +++ b/src/switch_log.c @@ -347,9 +347,11 @@ SWITCH_DECLARE(void) switch_log_vprintf(switch_text_channel_t channel, const cha const char *extra_fmt = "%s [%s] %s:%d%c%s"; #endif switch_log_level_t limit_level = runtime.hard_log_level; + switch_log_level_t special_level = SWITCH_LOG_UNINIT; if (channel == SWITCH_CHANNEL_ID_SESSION && userdata) { switch_core_session_t *session = (switch_core_session_t *) userdata; + special_level = session->loglevel; if (limit_level < session->loglevel) { limit_level = session->loglevel; } @@ -478,11 +480,13 @@ SWITCH_DECLARE(void) switch_log_vprintf(switch_text_channel_t channel, const cha switch_set_string(node->func, funcp); node->line = line; node->level = level; + node->slevel = special_level; node->content = content; node->timestamp = now; node->channel = channel; if (channel == SWITCH_CHANNEL_ID_SESSION) { - node->userdata = userdata ? strdup(switch_core_session_get_uuid((switch_core_session_t *) userdata)) : NULL; + switch_core_session_t *session = (switch_core_session_t *) userdata; + node->userdata = userdata ? strdup(switch_core_session_get_uuid(session)) : NULL; } else { node->userdata = !zstr(userdata) ? strdup(userdata) : NULL; }