diff --git a/plugin/business/pangu-http/src/pangu_logger.cpp b/plugin/business/pangu-http/src/pangu_logger.cpp index 862f0b5..4ba4f93 100644 --- a/plugin/business/pangu-http/src/pangu_logger.cpp +++ b/plugin/business/pangu-http/src/pangu_logger.cpp @@ -27,6 +27,10 @@ struct pangu_logger { char local_ip_str[TFE_SYMBOL_MAX]; int entry_id; + + unsigned int en_sendlog; + unsigned int en_sendlog_meta; + unsigned int en_sendlog_body; unsigned int local_ip_nr; void* global_logger; @@ -43,7 +47,6 @@ struct pangu_logger 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) @@ -110,7 +113,26 @@ struct pangu_logger* pangu_log_handle_create(const char* profile, const char* s struct pangu_logger* instance=ALLOC(struct pangu_logger,1); instance->local_logger=local_logger; - TFE_LOG_ERROR(local_logger,"Pangu log is inititating from %s section %s.", profile, section); + TFE_LOG_INFO(local_logger,"Pangu log is inititating from %s section %s.", profile, section); + + MESA_load_profile_uint_def(profile, section, "en_sendlog", &instance->en_sendlog, 1); + MESA_load_profile_uint_def(profile, section, "en_sendlog_meta", &instance->en_sendlog_meta, 1); + MESA_load_profile_uint_def(profile, section, "en_sendlog_body", &instance->en_sendlog_body, 1); + + if (!instance->en_sendlog) + { + instance->en_sendlog_body = 0; + instance->en_sendlog_meta = 0; + } + + TFE_LOG_INFO(local_logger, "Pangu sendlog : %s", instance->en_sendlog ? "ENABLE" : "DISABLE"); + TFE_LOG_INFO(local_logger, "Pangu sendlog meta : %s", instance->en_sendlog_meta ? "ENABLE" : "DISABLE"); + TFE_LOG_INFO(local_logger, "Pangu sendlog body : %s", instance->en_sendlog_body ? "ENABLE" : "DISABLE"); + + if (!instance->en_sendlog) + { + return instance; + } MESA_load_profile_string_def(profile, section, "NIC_NAME",nic_name,sizeof(nic_name),"eth0"); instance->local_ip_nr=get_ip_by_eth_name(nic_name); @@ -119,27 +141,27 @@ struct pangu_logger* pangu_log_handle_create(const char* profile, const char* s TFE_LOG_ERROR(local_logger, "%s get NIC_NAME: %s error.", __FUNCTION__, nic_name); goto error_out; } + inet_ntop(AF_INET,&(instance->local_ip_nr),instance->local_ip_str,sizeof(instance->local_ip_str)); MESA_load_profile_int_def(profile, section, "ENTRANCE_ID",&(instance->entry_id),0); - ret=MESA_load_profile_string_def(profile, section,"KAFKA_BROKERLIST", instance->brokerlist, sizeof(instance->brokerlist), NULL); if(ret<0) { TFE_LOG_ERROR(local_logger,"Pangu log init failed, no brokerlist in profile %s section %s.", profile, section); goto error_out; } + instance->kafka_handle=create_kafka_handle(instance->brokerlist); if(instance->kafka_handle==NULL) { TFE_LOG_ERROR(local_logger,"Pangu log init failed. Cannot create lafka handle with brokerlist: %s.", instance->brokerlist); goto error_out; } + 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; @@ -171,6 +193,11 @@ int pangu_send_log(struct pangu_logger* handle, const struct pangu_log* log_msg) struct json_spec resp_fields[]={ {"content_type", TFE_HTTP_CONT_TYPE}, {"content_len", TFE_HTTP_CONT_LENGTH} }; + if (!handle->en_sendlog) + { + return 0; + } + common_obj=cJSON_CreateObject(); cur_time = time(NULL);