输出非结构化日志。
This commit is contained in:
@@ -14,6 +14,8 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include <tfe_utils.h>
|
||||
#include <cache_evbase_client.h>
|
||||
|
||||
#include "pangu_logger.h"
|
||||
|
||||
struct json_spec
|
||||
@@ -40,6 +42,8 @@ struct pangu_logger
|
||||
unsigned long long random_drop;
|
||||
unsigned long long user_abort;
|
||||
char local_log_path[TFE_STRING_MAX];
|
||||
struct cache_evbase_instance * log_file_upload_instance;
|
||||
|
||||
};
|
||||
|
||||
static unsigned int get_ip_by_eth_name(const char *ifname)
|
||||
@@ -101,6 +105,7 @@ struct pangu_logger* pangu_log_handle_create(const char* profile, const char* s
|
||||
{
|
||||
int ret=-1;
|
||||
char nic_name[64]={0};
|
||||
struct tango_cache_parameter *log_file_upload_para=NULL;
|
||||
|
||||
struct pangu_logger* instance=ALLOC(struct pangu_logger,1);
|
||||
instance->local_logger=local_logger;
|
||||
@@ -132,6 +137,10 @@ struct pangu_logger* pangu_log_handle_create(const char* profile, const char* s
|
||||
}
|
||||
instance->topic_name="PXY-HTTP-LOG";
|
||||
instance->kafka_topic = rd_kafka_topic_new(instance->kafka_handle,instance->topic_name, NULL);
|
||||
|
||||
log_file_upload_para=cache_evbase_parameter_new(profile, section, local_logger);
|
||||
|
||||
instance->log_file_upload_instance=cache_evbase_instance_new(log_file_upload_para, local_logger);
|
||||
pthread_mutex_init(&(instance->mutex), NULL);
|
||||
return instance;
|
||||
|
||||
@@ -149,6 +158,7 @@ int pangu_send_log(struct pangu_logger* handle, const struct pangu_log* log_msg)
|
||||
char* log_payload=NULL;
|
||||
int kafka_status=0;
|
||||
int send_cnt=0;
|
||||
int tmp=0;
|
||||
time_t cur_time;
|
||||
char src_ip_str[MAX(INET6_ADDRSTRLEN,INET_ADDRSTRLEN)] = {0};
|
||||
char dst_ip_str[MAX(INET6_ADDRSTRLEN,INET_ADDRSTRLEN)] = {0};
|
||||
@@ -215,6 +225,63 @@ int pangu_send_log(struct pangu_logger* handle, const struct pangu_log* log_msg)
|
||||
cJSON_AddStringToObject(common_obj,resp_fields[i].log_filed_name, tmp_val);
|
||||
}
|
||||
}
|
||||
char log_file_upload_path[TFE_STRING_MAX]={0}, cont_type_whole[TFE_STRING_MAX]={0};
|
||||
struct tango_cache_meta_put meta;
|
||||
char* log_file_key=NULL;;
|
||||
const char* cont_type_val;
|
||||
if(log_msg->req_body!=NULL)
|
||||
{
|
||||
memset(&meta, 0, sizeof(meta));
|
||||
asprintf(&log_file_key, "%s.reqbody", http->req->req_spec.url);
|
||||
meta.url=log_file_key;
|
||||
cont_type_val=tfe_http_std_field_read(http->req, TFE_HTTP_CONT_TYPE);
|
||||
if(cont_type_val!=NULL)
|
||||
{
|
||||
snprintf(cont_type_whole, sizeof(cont_type_whole), "Content-Type:%s", cont_type_val);
|
||||
meta.std_hdr[0]=cont_type_whole;
|
||||
}
|
||||
tmp=cache_evbase_upload_once_evbuf(handle->log_file_upload_instance, NULL,
|
||||
log_msg->req_body,
|
||||
&meta,
|
||||
log_file_upload_path, sizeof(log_file_upload_path));
|
||||
if(tmp==0)
|
||||
{
|
||||
cJSON_AddStringToObject(common_obj, "req_body", log_file_upload_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
TFE_LOG_ERROR(handle->local_logger, "Upload req_body failed.");
|
||||
}
|
||||
free(log_file_key);
|
||||
}
|
||||
if(log_msg->resp_body!=NULL)
|
||||
{
|
||||
memset(&meta, 0, sizeof(meta));
|
||||
asprintf(&log_file_key, "%s.respbody", http->req->req_spec.url);
|
||||
meta.url=log_file_key;
|
||||
cont_type_val=tfe_http_std_field_read(http->resp, TFE_HTTP_CONT_TYPE);
|
||||
if(cont_type_val!=NULL)
|
||||
{
|
||||
snprintf(cont_type_whole, sizeof(cont_type_whole), "Content-Type:%s", cont_type_val);
|
||||
meta.std_hdr[0]=cont_type_whole;
|
||||
}
|
||||
tmp=cache_evbase_upload_once_evbuf(handle->log_file_upload_instance, NULL,
|
||||
log_msg->resp_body,
|
||||
&meta,
|
||||
log_file_upload_path, sizeof(log_file_upload_path));
|
||||
|
||||
if(tmp==0)
|
||||
{
|
||||
cJSON_AddStringToObject(common_obj, "resp_body", log_file_upload_path);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
TFE_LOG_ERROR(handle->local_logger, "Upload resp_body failed.");
|
||||
}
|
||||
free(log_file_key);
|
||||
}
|
||||
|
||||
for(size_t i=0; i<log_msg->result_num; i++)
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user