forked from Mirrors/freeswitch
FS-11693 [core] Added switch_channel_set_log_tag() and switch_channel_get_log_tags() This allows you to add log tags to an active call channel. If using SWITCH_CHANNEL_SESSION_LOG, with switch_log_printf(), the tags will be added to the the log node so a logging module can send additional contextual data to a log aggregator.
This commit is contained in:
parent
2e319c41c0
commit
e4c0abf286
@ -270,6 +270,9 @@ SWITCH_DECLARE(char *) switch_channel_get_uuid(switch_channel_t *channel);
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_channel_set_profile_var(switch_channel_t *channel, const char *name, const char *val);
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_channel_set_log_tag(switch_channel_t *channel, const char *tagname, const char *tagvalue);
|
||||
SWITCH_DECLARE(switch_status_t) switch_channel_get_log_tags(switch_channel_t *channel, switch_event_t **log_tags);
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_var_check(switch_channel_t *channel,
|
||||
const char *varname, const char *value, switch_bool_t var_check);
|
||||
SWITCH_DECLARE(switch_status_t) switch_channel_add_variable_var_check(switch_channel_t *channel,
|
||||
|
@ -65,6 +65,7 @@ SWITCH_BEGIN_EXTERN_C
|
||||
/* 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_event_t *tags;
|
||||
} switch_log_node_t;
|
||||
|
||||
typedef switch_status_t (*switch_log_function_t) (const switch_log_node_t *node, switch_log_level_t level);
|
||||
|
@ -176,6 +176,7 @@ struct switch_channel {
|
||||
switch_hold_record_t *hold_record;
|
||||
switch_device_node_t *device_node;
|
||||
char *device_id;
|
||||
switch_event_t *log_tags;
|
||||
};
|
||||
|
||||
static void process_device_hup(switch_channel_t *channel);
|
||||
@ -741,6 +742,9 @@ SWITCH_DECLARE(void) switch_channel_uninit(switch_channel_t *channel)
|
||||
switch_event_destroy(&channel->api_list);
|
||||
switch_event_destroy(&channel->var_list);
|
||||
switch_event_destroy(&channel->app_list);
|
||||
if (channel->log_tags) {
|
||||
switch_event_destroy(&channel->log_tags);
|
||||
}
|
||||
switch_mutex_unlock(channel->profile_mutex);
|
||||
}
|
||||
|
||||
@ -1412,6 +1416,37 @@ SWITCH_DECLARE(void) switch_channel_set_presence_data_vals(switch_channel_t *cha
|
||||
switch_safe_free(data_copy);
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_channel_set_log_tag(switch_channel_t *channel, const char *tagname, const char *tagvalue)
|
||||
{
|
||||
switch_status_t status = SWITCH_STATUS_FALSE;
|
||||
switch_assert(channel != NULL);
|
||||
switch_mutex_lock(channel->profile_mutex);
|
||||
if (!zstr(tagname)) {
|
||||
if (!channel->log_tags) {
|
||||
switch_event_create_plain(&channel->log_tags, SWITCH_EVENT_CHANNEL_DATA);
|
||||
}
|
||||
if (zstr(tagvalue)) {
|
||||
switch_event_del_header(channel->log_tags, tagname);
|
||||
} else {
|
||||
switch_event_add_header_string(channel->log_tags, SWITCH_STACK_BOTTOM, tagname, tagvalue);
|
||||
}
|
||||
status = SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
switch_mutex_unlock(channel->profile_mutex);
|
||||
return status;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_channel_get_log_tags(switch_channel_t *channel, switch_event_t **log_tags)
|
||||
{
|
||||
switch_status_t status = SWITCH_STATUS_FALSE;
|
||||
switch_assert(channel != NULL);
|
||||
switch_mutex_lock(channel->profile_mutex);
|
||||
if (channel->log_tags && log_tags) {
|
||||
status = switch_event_dup(log_tags, channel->log_tags);
|
||||
}
|
||||
switch_mutex_unlock(channel->profile_mutex);
|
||||
return status;
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_var_check(switch_channel_t *channel,
|
||||
const char *varname, const char *value, switch_bool_t var_check)
|
||||
|
@ -125,6 +125,10 @@ SWITCH_DECLARE(switch_log_node_t *) switch_log_node_dup(const switch_log_node_t
|
||||
switch_assert(newnode->userdata);
|
||||
}
|
||||
|
||||
if (node->tags) {
|
||||
switch_event_dup(&newnode->tags, node->tags);
|
||||
}
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
||||
@ -141,6 +145,9 @@ SWITCH_DECLARE(void) switch_log_node_free(switch_log_node_t **pnode)
|
||||
if (node) {
|
||||
switch_safe_free(node->userdata);
|
||||
switch_safe_free(node->data);
|
||||
if (node->tags) {
|
||||
switch_event_destroy(&node->tags);
|
||||
}
|
||||
#ifdef SWITCH_LOG_RECYCLE
|
||||
if (switch_queue_trypush(LOG_RECYCLE_QUEUE, node) != SWITCH_STATUS_SUCCESS) {
|
||||
free(node);
|
||||
@ -490,9 +497,13 @@ SWITCH_DECLARE(void) switch_log_vprintf(switch_text_channel_t channel, const cha
|
||||
node->content = content;
|
||||
node->timestamp = now;
|
||||
node->channel = channel;
|
||||
node->tags = NULL;
|
||||
if (channel == SWITCH_CHANNEL_ID_SESSION) {
|
||||
switch_core_session_t *session = (switch_core_session_t *) userdata;
|
||||
node->userdata = userdata ? strdup(switch_core_session_get_uuid(session)) : NULL;
|
||||
if (session) {
|
||||
switch_channel_get_log_tags(switch_core_session_get_channel(session), &node->tags);
|
||||
}
|
||||
} else {
|
||||
node->userdata = !zstr(userdata) ? strdup(userdata) : NULL;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user