2019-08-12 08:56:52 +00:00
|
|
|
#ifndef _LOGGING_COMMON_H
|
|
|
|
#define _LOGGING_COMMON_H
|
|
|
|
|
2019-08-12 10:12:53 +00:00
|
|
|
#include "cjson/cJSON.h"
|
|
|
|
#include "ulog_api.h"
|
|
|
|
#include "common_types.h"
|
|
|
|
#include "configm.h"
|
|
|
|
#include "configmapi.h"
|
|
|
|
#include "s2j/s2j.h"
|
|
|
|
|
|
|
|
|
2019-08-12 08:56:52 +00:00
|
|
|
#define DEFAULT_LOG_LEVEL "info"
|
|
|
|
|
|
|
|
extern ulog_t *g_log;
|
|
|
|
|
2019-08-27 08:45:48 +00:00
|
|
|
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);
|
2019-09-04 07:33:56 +00:00
|
|
|
void logging_get_terminal_console_print(void *log_conf, uint64 config_id);
|
2019-08-12 10:12:53 +00:00
|
|
|
|
2019-08-27 00:49:47 +00:00
|
|
|
|
|
|
|
#define CONF_TERMINAL(type, config_type, json_obj, str_level, on, module_name, conf_id) { \
|
2019-08-12 10:12:53 +00:00
|
|
|
type terminal = {0}; \
|
2019-08-27 00:49:47 +00:00
|
|
|
type terminal_out = {0}; \
|
2019-08-13 08:25:43 +00:00
|
|
|
int level; \
|
2019-08-27 08:45:48 +00:00
|
|
|
char *json_output = NULL; \
|
2019-08-12 10:12:53 +00:00
|
|
|
\
|
|
|
|
if ((level = log_str_to_level(str_level)) < 0) { \
|
|
|
|
ULOG_WARNING(g_log, "Unknown log level:%s", str_level); \
|
|
|
|
return -1; \
|
|
|
|
} \
|
|
|
|
\
|
2019-08-13 08:25:43 +00:00
|
|
|
terminal.level = (u8)level; \
|
2019-08-12 10:12:53 +00:00
|
|
|
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); \
|
|
|
|
\
|
2019-08-27 00:49:47 +00:00
|
|
|
int ret = set_log_conf(config_type, json_obj, conf_id, &json_output); \
|
2019-08-12 10:12:53 +00:00
|
|
|
if (ret != 0) { \
|
2019-08-13 08:25:43 +00:00
|
|
|
ULOG_ERR(g_log, "Setting terminal configure of log is failure"); \
|
2019-08-13 10:22:20 +00:00
|
|
|
} else { \
|
|
|
|
ULOG_DEBUG(g_log, "Setting terminal configure of log is success"); \
|
2019-08-12 10:12:53 +00:00
|
|
|
} \
|
2019-08-27 00:49:47 +00:00
|
|
|
\
|
|
|
|
if (CM_CONFIG_GET == config_type) { \
|
|
|
|
if (logging_terminal_json_parse(json_output, &terminal_out, conf_id) == 0) { \
|
2019-09-04 07:33:56 +00:00
|
|
|
logging_get_terminal_console_print(&terminal_out, conf_id); \
|
2019-08-27 00:49:47 +00:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
2019-08-12 10:12:53 +00:00
|
|
|
return ret; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CMD_PARSE_AND_CONFIG_TERMINAL(type, json_obj, argc, argv, conf_id) { \
|
|
|
|
log_sw_t on = LOG_ON; \
|
2019-08-27 08:45:48 +00:00
|
|
|
char *str_level = DEFAULT_LOG_LEVEL; \
|
2019-08-27 00:49:47 +00:00
|
|
|
uint config_type = CM_CONFIG_SET; \
|
|
|
|
\
|
2019-08-12 10:12:53 +00:00
|
|
|
if (argc >= 3) { \
|
|
|
|
if (strcasecmp(argv[2], "off") == 0) { \
|
|
|
|
on = LOG_OFF; \
|
2019-08-27 00:49:47 +00:00
|
|
|
} else if (strcasecmp(argv[2], "get") == 0) { \
|
|
|
|
config_type = CM_CONFIG_GET; \
|
2019-08-12 10:12:53 +00:00
|
|
|
} else { \
|
|
|
|
str_level = argv[2]; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
char *module = NULL; \
|
|
|
|
if (argc >= 4) { \
|
|
|
|
module = argv[3]; \
|
|
|
|
} \
|
|
|
|
\
|
2019-08-27 00:49:47 +00:00
|
|
|
CONF_TERMINAL(type, config_type, json_obj, str_level, on, module, conf_id); \
|
2019-08-12 10:12:53 +00:00
|
|
|
}
|
|
|
|
|
2019-08-12 08:56:52 +00:00
|
|
|
#endif
|