2019-08-12 10:12:53 +00:00
|
|
|
#include "logging_common.h"
|
|
|
|
#include "ulog_api.h"
|
|
|
|
#include "log_types.h"
|
|
|
|
#include "configm.h"
|
|
|
|
#include "configmapi.h"
|
|
|
|
#include "ulog/ulog_in.h"
|
|
|
|
|
2019-08-27 00:49:47 +00:00
|
|
|
|
|
|
|
|
2019-08-27 08:45:48 +00:00
|
|
|
int set_log_conf(uint config_type, cJSON *json_obj, uint64 config_id, char **json_output)
|
2019-08-12 10:12:53 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
char *output;
|
|
|
|
int output_len;
|
|
|
|
|
|
|
|
char *json = cJSON_PrintUnformatted(json_obj);
|
|
|
|
if (json == NULL) {
|
|
|
|
ULOG_ERR(g_log, "Converting struct to json is failure");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULOG_DEBUG(g_log, "Setting log json is %s", json);
|
2019-08-27 00:49:47 +00:00
|
|
|
|
|
|
|
ret_code ret_c = web_config_exec_sync(config_type, config_id,
|
2019-08-12 10:12:53 +00:00
|
|
|
json, strlen(json),
|
|
|
|
&output, &output_len);
|
|
|
|
if (ret_c != RET_OK) {
|
|
|
|
ULOG_ERR(g_log, "Log of Web config is failure:%d", ret_c);
|
|
|
|
} else {
|
|
|
|
ret = 0;
|
|
|
|
}
|
2019-08-27 00:49:47 +00:00
|
|
|
|
|
|
|
if ((CM_CONFIG_GET == config_type || CM_CONFIG_GET_ALL == config_type) && json_output != NULL)
|
|
|
|
{
|
|
|
|
ULOG_DEBUG(g_log, "get outputlen:%d, output:%s", output_len, output);
|
|
|
|
*json_output = output;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*json_output = NULL;
|
|
|
|
}
|
2019-08-12 10:12:53 +00:00
|
|
|
|
|
|
|
if (json != NULL) {
|
|
|
|
free(json);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-08-27 00:49:47 +00:00
|
|
|
|
2019-08-27 08:45:48 +00:00
|
|
|
int logging_terminal_json_parse(pointer input, pointer config_buff, uint64 conf_id)
|
2019-08-27 00:49:47 +00:00
|
|
|
{
|
|
|
|
cJSON *json_obj = NULL;
|
|
|
|
|
|
|
|
if (NULL == config_buff) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
json_obj = cJSON_Parse(input);
|
|
|
|
if (!json_obj)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
s2j_create_struct_obj(log_terminal, log_console_t);
|
|
|
|
if (NULL == log_terminal)
|
|
|
|
{
|
|
|
|
cJSON_Delete(json_obj);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
s2j_struct_get_basic_element(log_terminal, json_obj, int, level);
|
|
|
|
s2j_struct_get_basic_element(log_terminal, json_obj, int, on);
|
|
|
|
s2j_struct_get_basic_element(log_terminal, json_obj, string, module);
|
|
|
|
|
|
|
|
memcpy(config_buff, log_terminal, sizeof(log_console_t));
|
|
|
|
|
2019-09-05 07:43:18 +00:00
|
|
|
s2j_delete_struct_obj(log_terminal);
|
2019-08-27 00:49:47 +00:00
|
|
|
cJSON_Delete(json_obj);
|
|
|
|
|
|
|
|
return 0;
|
2019-09-04 07:33:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void logging_get_terminal_console_print(void *log_conf, uint64 config_id)
|
|
|
|
{
|
|
|
|
log_console_t *conf = log_conf;
|
|
|
|
if (NULL == conf)
|
|
|
|
{
|
|
|
|
return;
|
2019-08-27 00:49:47 +00:00
|
|
|
}
|
2019-09-04 07:33:56 +00:00
|
|
|
|
|
|
|
fprintf(stdout, "--------------------------------------------------------------------------------\n");
|
|
|
|
fprintf(stdout, " get %s:\n\n", config_id==LOG_CONFIG_CONSOLE?"console":"terminal");
|
|
|
|
if (conf->level < sizeof(g_level_array) / sizeof(level_str_t))
|
|
|
|
fprintf(stdout, " level %s\n", g_level_array[conf->level].str);
|
|
|
|
else
|
|
|
|
fprintf(stdout, " level <invalid_value>\n");
|
|
|
|
fprintf(stdout, " on/off %s\n", conf->on==LOG_ON?"on":"off");
|
|
|
|
fprintf(stdout, " module %s\n", conf->module);
|
|
|
|
fprintf(stdout, "--------------------------------------------------------------------------------\n");
|
|
|
|
|
|
|
|
if (LOG_ON == conf->on) {
|
|
|
|
ULOG_DEBUG(g_log, "Log %s get: level=%u, module=%s",
|
|
|
|
(config_id == LOG_CONFIG_CONSOLE)?"console":"monitor",
|
|
|
|
conf->level,
|
|
|
|
conf->module);
|
|
|
|
} else {
|
|
|
|
ULOG_DEBUG(g_log, "Log %s get: off",
|
|
|
|
(config_id == LOG_CONFIG_CONSOLE)?"console":"monitor");
|
|
|
|
}
|
|
|
|
}
|
2019-08-27 00:49:47 +00:00
|
|
|
|