#ifndef _LOGGING_COMMON_H #define _LOGGING_COMMON_H #include "cjson/cJSON.h" #include "ulog_api.h" #include "common_types.h" #include "configm.h" #include "configmapi.h" #include "s2j/s2j.h" #define DEFAULT_LOG_LEVEL "info" extern ulog_t *g_log; int set_log_conf(uint config_type, cJSON *json_obj, uint64 config_id, char **json_output); int logging_terminal_json_parse(pointer input, pointer config_buff, uint64 conf_id); void logging_get_terminal_console_print(void *log_conf, uint64 config_id); #define CONF_TERMINAL(type, config_type, json_obj, str_level, on, module_name, conf_id) { \ type terminal = {0}; \ type terminal_out = {0}; \ int level; \ char *json_output = NULL; \ \ if ((level = log_str_to_level(str_level)) < 0) { \ ULOG_WARNING(g_log, "Unknown log level:%s", str_level); \ return -1; \ } \ \ terminal.level = (u8)level; \ terminal.on = on; \ if (module_name != NULL) { \ strncpy(terminal.module, module_name, sizeof(terminal.module)); \ } \ \ s2j_json_set_basic_element(json_obj, &terminal, int, level); \ s2j_json_set_basic_element(json_obj, &terminal, int, on); \ s2j_json_set_basic_element(json_obj, &terminal, string, module); \ \ int ret = set_log_conf(config_type, json_obj, conf_id, &json_output); \ if (ret != 0) { \ ULOG_ERR(g_log, "Setting terminal configure of log is failure"); \ } else { \ ULOG_DEBUG(g_log, "Setting terminal configure of log is success"); \ } \ \ if (CM_CONFIG_GET == config_type) { \ if (logging_terminal_json_parse(json_output, &terminal_out, conf_id) == 0) { \ logging_get_terminal_console_print(&terminal_out, conf_id); \ } \ } \ \ return ret; \ } #define CMD_PARSE_AND_CONFIG_TERMINAL(type, json_obj, argc, argv, conf_id) { \ log_sw_t on = LOG_ON; \ char *str_level = DEFAULT_LOG_LEVEL; \ uint config_type = CM_CONFIG_SET; \ \ if (argc >= 3) { \ if (strcasecmp(argv[2], "off") == 0) { \ on = LOG_OFF; \ } else if (strcasecmp(argv[2], "get") == 0) { \ config_type = CM_CONFIG_GET; \ } else { \ str_level = argv[2]; \ } \ } \ \ char *module = NULL; \ if (argc >= 4) { \ module = argv[3]; \ } \ \ CONF_TERMINAL(type, config_type, json_obj, str_level, on, module, conf_id); \ } #endif