Add aaa-12 add log cmd remote
RCA: SOL: 修改人:zhangtao 检视人:
This commit is contained in:
parent
4ce9009899
commit
55671103ce
|
@ -1,5 +1,5 @@
|
|||
#ifndef _LOG_CONFIG_API_H
|
||||
#define _LOG_CONFIG_API_H
|
||||
#ifndef _LOG_TYPES_H
|
||||
#define _LOG_TYPES_H
|
||||
|
||||
#include "ulog_api.h"
|
||||
|
||||
|
@ -16,4 +16,20 @@ typedef struct _log_console {
|
|||
|
||||
typedef log_console_t log_pty_t;
|
||||
|
||||
typedef enum {
|
||||
LOG_RFC_UNKNOWN = -1,
|
||||
LOG_RFC_3164 = 0,
|
||||
LOG_RFC_5424
|
||||
} log_rfc_t;
|
||||
|
||||
typedef struct _log_remote_host {
|
||||
log_rfc_t rfc;
|
||||
char host[256];
|
||||
u16 port;
|
||||
} log_remote_host_t;
|
||||
|
||||
typedef struct _log_remote_level {
|
||||
u8 level;
|
||||
} log_remote_level_t;
|
||||
|
||||
#endif
|
|
@ -34,7 +34,7 @@ COMMON_SRCS = configserver.c \
|
|||
web_config/authfree.c web_config/auth_parameters.c\
|
||||
user_manager_config/user_group_config.c user_manager_config/user_account_config.c user_manager_config/usermanager-server/array_index.c \
|
||||
user_manager_config/usermanager-server/user_group.c user_manager_config/usermanager-server/user_mod.c user_manager_config/usermanager-server/user.c \
|
||||
log_config/log_config_console.c log_config/log_config_init.c
|
||||
log_config/log_config_console.c log_config/log_config_init.c log_config/log_config_cm.c log_config/log_config_monitor.c log_config/log_config_remote.c
|
||||
|
||||
# MRS Board Source Files
|
||||
PLAT_LINUX_SRCS = $(COMMON_SRCS)
|
||||
|
|
|
@ -27,7 +27,7 @@ VPATH = ../user/logging
|
|||
|
||||
# set the source file, don't used .o because of ...
|
||||
|
||||
COMMON_SRCS = logging_main.c cmd_console.c logging_common.c cmd_monitor.c
|
||||
COMMON_SRCS = logging_main.c cmd_console.c logging_common.c cmd_monitor.c cmd_remote.c
|
||||
|
||||
# MRS Board Source Files
|
||||
PLAT_LINUX_SRCS = $(COMMON_SRCS)
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <syslog.h>
|
||||
|
||||
#include "common_types.h"
|
||||
#include "log_types.h"
|
||||
|
||||
#define SERVICE_LOG_FILE_NAME "log-file"
|
||||
#define SERIVCE_LOG_CONSOLE_NAME "log-console"
|
||||
|
@ -11,12 +12,18 @@
|
|||
#define SERVICE_LOG_REMOTE_NAME "log-remote"
|
||||
|
||||
#define CONF_LOG_CONSOLE_FUNC "conf_log_console"
|
||||
#define CONF_LOG_PTY_FUNC "conf_log_pty"
|
||||
|
||||
typedef struct _level_str {
|
||||
u32 level;
|
||||
char str[10];
|
||||
} level_str_t;
|
||||
|
||||
typedef struct _rfc_key_fmt {
|
||||
log_rfc_t rfc;
|
||||
char fmt[20];
|
||||
} rfc_key_fmt;
|
||||
|
||||
static level_str_t g_level_array[] = {
|
||||
{LOG_EMERG, "emerg"},
|
||||
{LOG_ALERT, "alert"},
|
||||
|
@ -28,7 +35,12 @@ static level_str_t g_level_array[] = {
|
|||
{LOG_DEBUG, "debug"}
|
||||
};
|
||||
|
||||
static inline u8 log_str_to_level(const char *str_level)
|
||||
static rfc_key_fmt rfc_tbl[] = {
|
||||
{LOG_RFC_3164, "RFC3164fmt"},
|
||||
{LOG_RFC_5424, "RFC5424fmt"}
|
||||
};
|
||||
|
||||
static inline int log_str_to_level(const char *str_level)
|
||||
{
|
||||
int n = sizeof(g_level_array) / sizeof(level_str_t);
|
||||
for (int i = 0; i < n; i++) {
|
||||
|
|
|
@ -44,6 +44,13 @@
|
|||
|
||||
|
||||
#define LOG_CONFIG_CONSOLE (uint64)((uint64)LOG_CONFIG_MODULE<<32|1)
|
||||
#define LOG_CONFIG_MONITOR (uint64)((uint64)LOG_CONFIG_MODULE<<32|2)
|
||||
#define LOG_CONFIG_REMOTE_ADD_HOST (uint64)((uint64)LOG_CONFIG_MODULE<<32|3)
|
||||
#define LOG_CONFIG_REMOTE_DEL_HOST (uint64)((uint64)LOG_CONFIG_MODULE<<32|4)
|
||||
#define LOG_CONFIG_REMOTE_LEVEL (uint64)((uint64)LOG_CONFIG_MODULE<<32|5)
|
||||
|
||||
|
||||
|
||||
#define NAT4_CONFIG (uint64)((uint64)NAT_CONFIG_MODULE<<32|1)
|
||||
|
||||
#define CONFIG_INIT_ARRAY \
|
||||
|
@ -151,6 +158,33 @@
|
|||
log_console_config_proc, \
|
||||
NULL, \
|
||||
NULL \
|
||||
},\
|
||||
{\
|
||||
LOG_CONFIG_MONITOR, \
|
||||
CONFIG_FROM_WEB, \
|
||||
FALSE, \
|
||||
log_monitor_config_chk, \
|
||||
log_monitor_config_proc, \
|
||||
NULL, \
|
||||
NULL \
|
||||
},\
|
||||
{\
|
||||
LOG_CONFIG_REMOTE_ADD_HOST, \
|
||||
CONFIG_FROM_WEB, \
|
||||
FALSE, \
|
||||
log_remote_config_chk, \
|
||||
log_remote_add_config_proc, \
|
||||
NULL, \
|
||||
NULL \
|
||||
},\
|
||||
{\
|
||||
LOG_CONFIG_REMOTE_DEL_HOST, \
|
||||
CONFIG_FROM_WEB, \
|
||||
FALSE, \
|
||||
log_remote_config_chk, \
|
||||
log_remote_del_config_proc, \
|
||||
NULL, \
|
||||
NULL \
|
||||
}\
|
||||
}
|
||||
|
||||
|
|
|
@ -13,5 +13,20 @@ ret_code log_console_config_chk(uint source, uint *config_type,
|
|||
ret_code log_console_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
ret_code log_monitor_config_chk(uint source, uint *config_type,
|
||||
pointer input, int *input_len,
|
||||
pointer output, int *output_len);
|
||||
ret_code log_monitor_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
ret_code log_remote_config_chk(uint source, uint *config_type,
|
||||
pointer input, int *input_len,
|
||||
pointer output, int *output_len);
|
||||
ret_code log_remote_add_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
ret_code log_remote_del_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,20 @@
|
|||
#include "log_config_cm.h"
|
||||
#include "rpc_server.h"
|
||||
|
||||
ret_code log_rpc_exec(char* service_name, char* method_name, pointer input, int input_len, int last_lenth)
|
||||
{
|
||||
if ((input == NULL)
|
||||
&& input_len < last_lenth /*sizeof(log_console_t) */) {
|
||||
return RET_INPUTERR;
|
||||
}
|
||||
|
||||
ret_code ret = rpc_client_call(g_log_client, service_name,
|
||||
method_name, input, input_len, NULL, NULL);
|
||||
if (ret != RET_OK) {
|
||||
ULOG_ERR(g_log_h, "rpc call is failure[ret:%u, service:%s, method:%s]", ret, service_name, method_name);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
#ifndef _LOG_CONFIG_H_H
|
||||
#define _LOG_CONFIG_H_H
|
||||
|
||||
#include "log_types.h"
|
||||
#include "ulog_in.h"
|
||||
#include "cjson/cJSON.h"
|
||||
#include "s2j/s2j.h"
|
||||
#include "rpc_types.h"
|
||||
#include "rpc_common.h"
|
||||
|
||||
#define TERMINAL_CHK(type, input, input_len, str_conf) { \
|
||||
ULOG_DEBUG(g_log_h, "Checking %s configuration:%s", str_conf, input); \
|
||||
if (input == NULL) { \
|
||||
ULOG_ERR(g_log_h, "input can't null"); \
|
||||
return RET_INPUTERR; \
|
||||
} \
|
||||
\
|
||||
cJSON *json_obj = cJSON_Parse(input); \
|
||||
if(!json_obj) { \
|
||||
ULOG_ERR(g_log_h, "Error log %s format", str_conf); \
|
||||
return RET_INPUTERR; \
|
||||
} \
|
||||
\
|
||||
ULOG_DEBUG(g_log_h, "json input: %s", cJSON_Print(json_obj)); \
|
||||
\
|
||||
s2j_create_struct_obj(log_terminal, type /*log_console_t*/); \
|
||||
if(log_terminal == NULL) { \
|
||||
cJSON_Delete(json_obj); \
|
||||
ULOG_ERR(g_log_h, "Creating log %s of object is failure", str_conf); \
|
||||
return RET_NOMEM; \
|
||||
} \
|
||||
\
|
||||
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_STRING_ELEMENT_N(log_terminal, json_obj, module, MAX_MODULE_NAME_SZ); \
|
||||
\
|
||||
*input_len = sizeof(*log_terminal); \
|
||||
memcpy(input, log_terminal, *input_len); \
|
||||
\
|
||||
return RET_OK; \
|
||||
}
|
||||
|
||||
extern rpc_client *g_log_client;
|
||||
extern ulog_t *g_log_h;
|
||||
|
||||
ret_code log_rpc_exec(char* service_name, char* method_name, pointer input, int input_len, int last_lenth);
|
||||
|
||||
#endif
|
|
@ -1,63 +1,16 @@
|
|||
#include <cjson/cJSON.h>
|
||||
|
||||
#include "rpc_server.h"
|
||||
#include "log_config.h"
|
||||
#include "configm.h"
|
||||
#include "log_types.h"
|
||||
#include "ulog_in.h"
|
||||
#include "log_config_h.h"
|
||||
#include "log_config_cm.h"
|
||||
|
||||
ret_code log_console_config_chk(uint source, uint *config_type,
|
||||
pointer input, int *input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
if (input == NULL) {
|
||||
ULOG_ERR(g_log_h, "input can't null");
|
||||
return RET_INPUTERR;
|
||||
}
|
||||
|
||||
cJSON *json_obj = cJSON_Parse(input);
|
||||
if(!json_obj)
|
||||
{
|
||||
ULOG_ERR(g_log_h, "Error log console format");
|
||||
return RET_INPUTERR;
|
||||
}
|
||||
|
||||
ULOG_DEBUG(g_log_h, "json input: %s", cJSON_Print(json_obj));
|
||||
|
||||
s2j_create_struct_obj(log_console, log_console_t);
|
||||
if(log_console == NULL)
|
||||
{
|
||||
cJSON_Delete(json_obj);
|
||||
ULOG_ERR(g_log_h, "Creating log console of object is failure");
|
||||
return RET_NOMEM;
|
||||
}
|
||||
|
||||
s2j_struct_get_basic_element(log_console, json_obj, int, level);
|
||||
s2j_struct_get_basic_element(log_console, json_obj, int, on);
|
||||
S2J_STRUCT_GET_STRING_ELEMENT_N(log_console, json_obj, module, MAX_MODULE_NAME_SZ);
|
||||
|
||||
*input_len = sizeof(*log_console);
|
||||
memcpy(input, log_console, *input_len);
|
||||
|
||||
return RET_OK;
|
||||
TERMINAL_CHK(log_console_t, input, input_len, "console");
|
||||
}
|
||||
|
||||
ret_code log_console_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
if ((input == NULL)
|
||||
&& input_len < sizeof(log_console_t)) {
|
||||
return RET_INPUTERR;
|
||||
return log_rpc_exec(SERVICE_LOG_PTY_NAME, CONF_LOG_CONSOLE_FUNC, input, input_len, sizeof(log_console_t));
|
||||
}
|
||||
|
||||
ret_code ret = rpc_client_call(g_log_client, SERIVCE_LOG_CONSOLE_NAME,
|
||||
CONF_LOG_CONSOLE_FUNC, input, input_len, NULL, NULL);
|
||||
if (ret != RET_OK) {
|
||||
ULOG_ERR(g_log_h, "rpc call is failure[ret:%u, method:%s]", ret, CONF_LOG_CONSOLE_FUNC);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
#ifndef _LOG_CONFIG_H_H
|
||||
#define _LOG_CONFIG_H_H
|
||||
|
||||
extern rpc_client *g_log_client;
|
||||
extern ulog_t *g_log_h;
|
||||
|
||||
#endif
|
|
@ -0,0 +1,17 @@
|
|||
#include "log_config.h"
|
||||
#include "log_config_cm.h"
|
||||
|
||||
ret_code log_monitor_config_chk(uint source, uint *config_type,
|
||||
pointer input, int *input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
TERMINAL_CHK(log_console_t, input, input_len, "pty");
|
||||
}
|
||||
|
||||
ret_code log_monitor_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
return log_rpc_exec(SERVICE_LOG_PTY_NAME, CONF_LOG_PTY_FUNC, input, input_len, sizeof(log_console_t));
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
#include "log_config.h"
|
||||
#include "log_config_cm.h"
|
||||
|
||||
ret_code log_remote_config_chk(uint source, uint *config_type,
|
||||
pointer input, int *input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
TERMINAL_CHK(log_console_t, input, input_len, "pty");
|
||||
}
|
||||
|
||||
ret_code log_remote_add_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
return log_rpc_exec(SERVICE_LOG_PTY_NAME, CONF_LOG_PTY_FUNC, input, input_len, sizeof(log_console_t));
|
||||
}
|
||||
|
||||
ret_code log_remote_del_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
return log_rpc_exec(SERVICE_LOG_PTY_NAME, CONF_LOG_PTY_FUNC, input, input_len, sizeof(log_console_t));
|
||||
}
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
#include "cmd_console.h"
|
||||
#include "cmd_monitor.h"
|
||||
#include "ulog_api.h"
|
||||
#include "log_types.h"
|
||||
#include "logging_common.h"
|
||||
|
@ -7,7 +7,7 @@
|
|||
|
||||
int conf_monitor(cJSON *json_obj, int argc, char **argv)
|
||||
{
|
||||
CMD_PARSE_AND_CONFIG_TERMINAL(log_pty_t, json_obj, argc, argv, LOG_CONFIG_CONSOLE);
|
||||
CMD_PARSE_AND_CONFIG_TERMINAL(log_pty_t, json_obj, argc, argv, LOG_CONFIG_MONITOR);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
#include "cmd_remote.h"
|
||||
#include "logging_common.h"
|
||||
#include "common_types.h"
|
||||
#include "log_types.h"
|
||||
#include "ulog_in.h"
|
||||
#include "s2j/s2j.h"
|
||||
|
||||
#define DEFAULT_REMOTE_HOST 514
|
||||
|
||||
static log_rfc_t get_rfc_by_name(const char *name)
|
||||
{
|
||||
for (int i = 0; i < (sizeof(rfc_tbl) / sizeof(rfc_key_fmt)); i++) {
|
||||
if (strcasecmp(name, rfc_tbl[i].fmt) == 0) {
|
||||
return rfc_tbl[i].rfc;
|
||||
}
|
||||
}
|
||||
|
||||
return LOG_RFC_UNKNOWN;
|
||||
}
|
||||
|
||||
static int conf_remote_by_config_id(cJSON *json_obj, const char *host, const u16 port, const log_rfc_t rfc, uint64 config_id)
|
||||
{
|
||||
log_remote_host_t remote;
|
||||
|
||||
strncpy(remote.host, host, sizeof(remote.host));
|
||||
remote.port = port;
|
||||
remote.rfc = rfc;
|
||||
|
||||
s2j_json_set_basic_element(json_obj, &remote, int, port);
|
||||
s2j_json_set_basic_element(json_obj, &remote, int, rfc);
|
||||
s2j_json_set_basic_element(json_obj, &remote, string, host);
|
||||
|
||||
int ret = set_log_conf(json_obj, config_id);
|
||||
if (ret != 0) {
|
||||
ULOG_ERR(g_log, "Host of log which is configured is failure");
|
||||
}
|
||||
ULOG_DEBUG(g_log, "Host of log whice is configured is success");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int conf_remote(cJSON *json_obj, int argc, char **argv)
|
||||
{
|
||||
int ret = -1;
|
||||
uint64 config_id;
|
||||
|
||||
if (argc <= 3) {
|
||||
ULOG_WARNING(g_log, "Parameter too less");
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (strcasecmp(argv[2], "add") == 0) {
|
||||
config_id = LOG_CONFIG_REMOTE_ADD_HOST;
|
||||
} else if (strcasecmp(argv[2], "del") == 0) {
|
||||
config_id = LOG_CONFIG_REMOTE_DEL_HOST;
|
||||
} else {
|
||||
ULOG_WARNING(g_log, "Unknown operation command:%s", argv[2]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *host = argv[3];
|
||||
u16 port = DEFAULT_REMOTE_HOST;
|
||||
if (argc >= 5) {
|
||||
port= atoi(argv[4]);
|
||||
}
|
||||
|
||||
log_rfc_t rfc = LOG_RFC_3164;
|
||||
if (argc >= 6) {
|
||||
rfc = get_rfc_by_name(argv[5]);
|
||||
if (rfc == LOG_RFC_UNKNOWN) {
|
||||
ULOG_WARNING(g_log, "Unknown rfc standard:%s of log", argv[5]);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return conf_remote_by_config_id(json_obj, host, port, rfc, config_id);
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef _CMD_REMOTE_H
|
||||
#define _CMD_REMOTE_H
|
||||
|
||||
#include "cjson/cJSON.h"
|
||||
|
||||
int conf_remote(cJSON *json_obj, int argc, char **argv);
|
||||
|
||||
#endif
|
|
@ -18,7 +18,7 @@ int set_log_conf(cJSON *json_obj, uint64 config_id)
|
|||
}
|
||||
|
||||
ULOG_DEBUG(g_log, "Setting log json is %s", json);
|
||||
ret_code ret_c = web_config_exec_sync(CM_CONFIG_SET, config_id /*LOG_CONFIG_CONSOLE*/,
|
||||
ret_code ret_c = web_config_exec_sync(CM_CONFIG_SET, config_id,
|
||||
json, strlen(json),
|
||||
&output, &output_len);
|
||||
if (ret_c != RET_OK) {
|
||||
|
|
|
@ -17,14 +17,14 @@ 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}; \
|
||||
u8 level; \
|
||||
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 = level; \
|
||||
terminal.level = (u8)level; \
|
||||
terminal.on = on; \
|
||||
if (module_name != NULL) { \
|
||||
strncpy(terminal.module, module_name, sizeof(terminal.module)); \
|
||||
|
@ -36,9 +36,9 @@ int set_log_conf(cJSON *json_obj, uint64 config_id);
|
|||
\
|
||||
int ret = set_log_conf(json_obj, conf_id); \
|
||||
if (ret != 0) { \
|
||||
ULOG_ERR(g_log, "Setting configure of log is failure"); \
|
||||
ULOG_ERR(g_log, "Setting terminal configure of log is failure"); \
|
||||
} \
|
||||
ULOG_DEBUG(g_log, "Setting configure of log is success"); \
|
||||
ULOG_DEBUG(g_log, "Setting terminal configure of log is success"); \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "cmd_console.h"
|
||||
#include "cmd_monitor.h"
|
||||
#include "cmd_remote.h"
|
||||
#include "ulog_api.h"
|
||||
#include "s2j/s2j.h"
|
||||
|
||||
|
@ -15,16 +16,17 @@ typedef struct _log_cmd {
|
|||
} log_cmd_t;
|
||||
|
||||
ulog_t *g_log;
|
||||
log_cmd_t log_cmd[] = {
|
||||
log_cmd_t g_log_cmd[] = {
|
||||
{"console", conf_console},
|
||||
{"monitor", conf_monitor}
|
||||
{"monitor", conf_monitor},
|
||||
{"host", conf_remote}
|
||||
};
|
||||
|
||||
cmd_cb get_cb_by_cmd(const char *cmd)
|
||||
log_cmd_t *get_cb_by_cmd(const char *cmd)
|
||||
{
|
||||
for (int i = 0; i < (sizeof(log_cmd) / sizeof(log_cmd_t)); i++) {
|
||||
if (strcmp(cmd, log_cmd[i].cmd) == 0) {
|
||||
return log_cmd[i].cb;
|
||||
for (int i = 0; i < (sizeof(g_log_cmd) / sizeof(log_cmd_t)); i++) {
|
||||
if (strcasecmp(cmd, g_log_cmd[i].cmd) == 0) {
|
||||
return &g_log_cmd[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,19 +35,20 @@ cmd_cb get_cb_by_cmd(const char *cmd)
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret = -1;
|
||||
if (argc < 2) {
|
||||
fprintf(stdout, "Parameter too few");
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
g_log = ulog_init(LOGGING_MODULE_NAME, 1);
|
||||
if (g_log == NULL) {
|
||||
fprintf(stderr, "Initiating ulog is failure");
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
cmd_cb func = get_cb_by_cmd(argv[1]);
|
||||
if (func == NULL) {
|
||||
log_cmd_t *log_cmd = get_cb_by_cmd(argv[1]);
|
||||
if (log_cmd == NULL) {
|
||||
ULOG_WARNING(g_log, "Not find logging cmd:%s", argv[1]);
|
||||
goto END;
|
||||
}
|
||||
|
@ -57,12 +60,16 @@ int main(int argc, char **argv)
|
|||
goto END;
|
||||
}
|
||||
|
||||
func(json_obj, argc, argv);
|
||||
if (log_cmd->cb(json_obj, argc, argv) != 0) {
|
||||
ULOG_ERR(g_log, "Configuring %s is failure", log_cmd->cmd);
|
||||
goto END;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
END:
|
||||
if(json_obj != NULL) {
|
||||
cJSON_Delete(json_obj);
|
||||
}
|
||||
ulog_close(g_log);
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -206,4 +206,23 @@ int write_conf_content_authorizing(FILE *fp, const u8 level, const c
|
|||
return 0;
|
||||
}
|
||||
|
||||
int delete_conf_file(const char *path, const char *file_name)
|
||||
{
|
||||
char file[MAX_PATH_SZ];
|
||||
int ret = -1;
|
||||
|
||||
if (snprintf(file, sizeof(file), "%s%s", path, file_name) < 0) {
|
||||
ULOG_ERR(g_log, "Setting file path(dir:%s, file:%s) is failure",
|
||||
path, file_name);
|
||||
return ret;
|
||||
}
|
||||
if (unlink(file) < 0) {
|
||||
ULOG_ERR(g_log, "Deleting configure file(dir:%s, file:%s) is failure:%s",
|
||||
path, file_name, strerror(errno));
|
||||
return ret;
|
||||
}
|
||||
ret = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ int log_conf_append(const u8 level, const char *conf_path, const char *conf_file
|
|||
int write_conf_content(FILE *fp, const u8 level, const char *filter_mod, void *arg);
|
||||
int write_conf_content_authorizing(FILE *fp, const u8 level, const char *filter_mod, void *arg);
|
||||
int log_level_to_str(const u8 level, char *str, u32 len);
|
||||
int delete_conf_file(const char *path, const char *file_name);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include <errno.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "log_console.h"
|
||||
|
@ -54,33 +53,24 @@ static int write_console_content(FILE *fp, const u8 level, const char *filter_mo
|
|||
|
||||
static int config_log_console(const log_console_t *conf)
|
||||
{
|
||||
char file[MAX_PATH_SZ];
|
||||
int ret = 0;
|
||||
int ret = -1;
|
||||
|
||||
switch (conf->on)
|
||||
{
|
||||
case LOG_OFF:
|
||||
if (snprintf(file, sizeof(file), "%s%s", LOG_CONF_PATH, LOG_CONF_COSOLE_FILE_NAME) < 0) {
|
||||
ULOG_ERR(g_log, "Setting file path(dir:%s, file:%s) is failure",
|
||||
LOG_CONF_PATH, LOG_CONF_COSOLE_FILE_NAME);
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
if (unlink(file) < 0) {
|
||||
ULOG_ERR(g_log, "Deleting configure file(dir:%s, file:%s) is failure:%s",
|
||||
LOG_CONF_PATH, LOG_CONF_COSOLE_FILE_NAME, strerror(errno));
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
ret = delete_conf_file(LOG_CONF_PATH, LOG_CONF_COSOLE_FILE_NAME);
|
||||
break;
|
||||
case LOG_ON:
|
||||
if (log_conf(conf->level, LOG_CONF_PATH, LOG_CONF_COSOLE_FILE_NAME, conf->module,
|
||||
write_console_content, NULL) != 0) {
|
||||
ULOG_ERR(g_log, "Log's console configure which is written is failure");
|
||||
ret = -1;
|
||||
} else {
|
||||
ret = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ULOG_WARNING(g_log, "Unknown on value:%u", conf->on);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -98,6 +88,7 @@ void rpc_conf_log_console(rpc_conn *conn, pointer input, int input_len, pointer
|
|||
}
|
||||
|
||||
if (config_log_console((const log_console_t *)input) != 0) {
|
||||
ULOG_ERR(g_log, "Configuring console of log is faiure");
|
||||
rpc_return_error(conn, RET_ERR, "Configuring console of log is faiure");
|
||||
}
|
||||
rpc_return_null(conn);
|
||||
|
|
|
@ -52,13 +52,28 @@ static int write_pty_content(FILE *fp, const u8 level, const char *filter_mod, v
|
|||
|
||||
static int config_log_pty(const log_pty_t *conf)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
switch (conf->on)
|
||||
{
|
||||
case LOG_OFF:
|
||||
ret = delete_conf_file(LOG_CONF_PATH, LOG_CONF_PTY_FILE_NAME);
|
||||
break;
|
||||
case LOG_ON:
|
||||
if (log_conf(conf->level, LOG_CONF_PATH, LOG_CONF_PTY_FILE_NAME, conf->module,
|
||||
write_pty_content, NULL) != 0) {
|
||||
ULOG_ERR(g_log, "Log's pty configure which is written is failure");
|
||||
return -1;
|
||||
ret = -1;
|
||||
} else {
|
||||
ret = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ULOG_WARNING(g_log, "Unknown on value:%u", conf->on);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void rpc_conf_log_pty(rpc_conn *conn, pointer input, int input_len, pointer data)
|
||||
|
@ -71,6 +86,10 @@ void rpc_conf_log_pty(rpc_conn *conn, pointer input, int input_len, pointer data
|
|||
return;
|
||||
}
|
||||
|
||||
config_log_pty((const log_pty_t *)input);
|
||||
if (config_log_pty((const log_pty_t *)input) != 0) {
|
||||
ULOG_ERR(g_log, "Configuring pty of log is faiure");
|
||||
rpc_return_error(conn, RET_ERR, "Configuring pty of log is faiure");
|
||||
}
|
||||
rpc_return_null(conn);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
#include "log_remote.h"
|
||||
#include "log_common.h"
|
||||
#include "ulog_in.h"
|
||||
|
||||
|
||||
#define LOG_CONF_REMOTE_FILE_NAME "log-remote.conf"
|
||||
|
||||
|
@ -20,17 +22,6 @@ typedef enum {
|
|||
LOG_REMOTE_MAX
|
||||
} log_op_t;
|
||||
|
||||
|
||||
typedef struct _rfc_key_fmt {
|
||||
log_rfc_t rfc;
|
||||
char fmt[20];
|
||||
} rfc_key_fmt;
|
||||
|
||||
static rfc_key_fmt rfc_tbl[] = {
|
||||
{LOG_RFC_3164, "RFC3164fmt"},
|
||||
{LOG_RFC_5424, "RFC5424fmt"}
|
||||
};
|
||||
|
||||
typedef int (*op_func)(const log_remote_host_t *conf);
|
||||
|
||||
static int add_remote_host(const log_remote_host_t *conf);
|
||||
|
|
|
@ -4,21 +4,7 @@
|
|||
#include "ulog_api.h"
|
||||
#include "common_types.h"
|
||||
#include "rpc_common.h"
|
||||
|
||||
typedef enum {
|
||||
LOG_RFC_3164 = 0,
|
||||
LOG_RFC_5424
|
||||
} log_rfc_t;
|
||||
|
||||
typedef struct _log_remote_host {
|
||||
log_rfc_t rfc;
|
||||
char host[256];
|
||||
u16 port;
|
||||
} log_remote_host_t;
|
||||
|
||||
typedef struct _log_remote_level {
|
||||
u8 level;
|
||||
} log_remote_level_t;
|
||||
#include "log_types.h"
|
||||
|
||||
void rpc_conf_log_add_remote(rpc_conn *conn, pointer input, int input_len, pointer data);
|
||||
void rpc_conf_log_del_remote(rpc_conn *conn, pointer input, int input_len, pointer data);
|
||||
|
|
|
@ -86,7 +86,7 @@ int main(int argc, char **argv)
|
|||
/* 注册配置处理函数 */
|
||||
rpc_server_regservice(server, SERVICE_LOG_FILE_NAME, "conf_log_file", rpc_conf_log_file);
|
||||
rpc_server_regservice(server, SERIVCE_LOG_CONSOLE_NAME, CONF_LOG_CONSOLE_FUNC, rpc_conf_log_console);
|
||||
rpc_server_regservice(server, SERVICE_LOG_PTY_NAME, "conf_log_pty", rpc_conf_log_pty);
|
||||
rpc_server_regservice(server, SERVICE_LOG_PTY_NAME, CONF_LOG_PTY_FUNC, rpc_conf_log_pty);
|
||||
rpc_server_regservice(server, SERVICE_LOG_REMOTE_NAME, "conf_log_add_remote", rpc_conf_log_add_remote);
|
||||
rpc_server_regservice(server, SERVICE_LOG_REMOTE_NAME, "conf_log_del_remote", rpc_conf_log_del_remote);
|
||||
rpc_server_regservice(server, SERVICE_LOG_REMOTE_NAME, "conf_log_remote_level", rpc_conf_log_remote_level);
|
||||
|
|
Loading…
Reference in New Issue