修改日志字段common_service_category为数组格式

This commit is contained in:
fengweihao
2021-06-04 15:46:37 +08:00
parent 2ad0ddecbe
commit bd01e15472

View File

@@ -81,14 +81,11 @@ error_out:
return NULL;
}
static int pangu_log_get_fqdn_cat(struct tfe_cmsg *cmsg, char *fqdn_cat_buff)
static unsigned int pangu_log_get_fqdn_cat(struct tfe_cmsg *cmsg, unsigned int *category_id_val)
{
int ret=0;
unsigned int i=0, category_id_num=0;
unsigned category_id_num=0;
uint16_t opt_out_size;
unsigned int category_id_val[TFE_SYMBOL_MAX]={0};
char *p = fqdn_cat_buff;
ret = tfe_cmsg_get_value(cmsg, TFE_CMSG_FQDN_CAT_ID_NUM, (unsigned char *)&category_id_num, sizeof(category_id_num), &opt_out_size);
if (ret != 0 || category_id_num == 0)
@@ -101,12 +98,7 @@ static int pangu_log_get_fqdn_cat(struct tfe_cmsg *cmsg, char *fqdn_cat_buff)
return -1;
}
for (i = 0; i < category_id_num && i < 8; i++)
{
p += snprintf(p, sizeof(fqdn_cat_buff) - (p - fqdn_cat_buff), "%s%d", i>0 ? "," : "", category_id_val[i]);
}
return 0;
return category_id_num > 8 ? 8 : category_id_num;
}
int pangu_send_log(struct pangu_logger* handle, const struct pangu_log* log_msg)
@@ -153,9 +145,8 @@ int pangu_send_log(struct pangu_logger* handle, const struct pangu_log* log_msg)
cJSON_AddStringToObject(common_obj, "http_version", app_proto[http->major_version]);
cJSON_AddStringToObject(common_obj, "common_schema_type", "HTTP");
unsigned int common_direction=0;
char category_id_val[TFE_SYMBOL_MAX];
char opt_val[24] = { 0 }; uint16_t opt_out_size;
unsigned int common_direction=0, category_id_val[8]={0};
char opt_val[24]={0}; uint16_t opt_out_size;
struct tfe_cmsg * cmsg = tfe_stream_get0_cmsg(log_msg->stream);
if (cmsg!=NULL)
{
@@ -170,9 +161,9 @@ int pangu_send_log(struct pangu_logger* handle, const struct pangu_log* log_msg)
cJSON_AddNumberToObject(common_obj, "common_direction", common_direction); //0域内->域外1域外->域内描述的是CLIENT_IP信息
}
ret = pangu_log_get_fqdn_cat(cmsg, category_id_val);
if (ret==0)
if (ret>0)
{
cJSON_AddStringToObject(common_obj, "common_service_category", category_id_val);
cJSON_AddItemToObject(common_obj, "common_service_category", cJSON_CreateIntArray((const int*)category_id_val, ret));
}
}