secgateway/Platform/user/logging/logging_common.h

68 lines
4.2 KiB
C
Executable File

#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(cJSON *json_obj, uint64 config_id);
#define CONF_TERMINAL(type, json_obj, str_level, on, module_name, conf_id) { \
type terminal = {0}; \
int level; \
\
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(json_obj, conf_id); \
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"); \
} \
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; \
if (argc >= 3) { \
if (strcasecmp(argv[2], "off") == 0) { \
on = LOG_OFF; \
} else { \
str_level = argv[2]; \
} \
} \
\
char *module = NULL; \
if (argc >= 4) { \
module = argv[3]; \
} \
\
CONF_TERMINAL(type, json_obj, str_level, on, module, conf_id); \
}
#endif