parent
250ef8331a
commit
cde096997d
|
@ -38,8 +38,7 @@
|
|||
#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 LOG_CONFIG_FILE (uint64)((uint64)LOG_CONFIG_MODULE<<32|6)
|
||||
|
||||
#define NAT4_CONFIG (uint64)((uint64)NAT_CONFIG_MODULE<<32|1)
|
||||
|
||||
|
|
|
@ -5,6 +5,11 @@
|
|||
|
||||
#define LOG_HOST_SZ 256
|
||||
|
||||
|
||||
#define MAX_LINE_SZ 1024
|
||||
#define MAX_PATH_SZ MAX_LINE_SZ
|
||||
|
||||
|
||||
typedef enum {
|
||||
LOG_OFF = 0,
|
||||
LOG_ON
|
||||
|
@ -34,4 +39,18 @@ typedef struct _log_remote_level {
|
|||
u8 level;
|
||||
} log_remote_level_t;
|
||||
|
||||
typedef enum {
|
||||
LOG_UNCOMPRESS = 0,
|
||||
LOG_COMPRESS
|
||||
} log_compress_t;
|
||||
|
||||
typedef struct _log_file {
|
||||
u8 level;
|
||||
char path[MAX_PATH_SZ];
|
||||
log_compress_t is_compress;
|
||||
u32 del_over_days;
|
||||
u64 del_over_size;
|
||||
} log_file_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_cm.c log_config/log_config_monitor.c log_config/log_config_remote.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 log_config/log_config_file.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 cmd_remote.c
|
||||
COMMON_SRCS = logging_main.c cmd_console.c logging_common.c cmd_monitor.c cmd_remote.c cmd_file.c
|
||||
|
||||
# MRS Board Source Files
|
||||
PLAT_LINUX_SRCS = $(COMMON_SRCS)
|
||||
|
|
|
@ -11,10 +11,12 @@
|
|||
#define SERVICE_LOG_PTY_NAME "log-pty"
|
||||
#define SERVICE_LOG_REMOTE_NAME "log-remote"
|
||||
|
||||
#define CONF_LOG_FILE_FUNC "conf_log_file"
|
||||
#define CONF_LOG_CONSOLE_FUNC "conf_log_console"
|
||||
#define CONF_LOG_PTY_FUNC "conf_log_pty"
|
||||
#define CONF_LOG_REMOTE_ADD_HOST "conf_log_add_remote"
|
||||
#define CONF_LOG_REMOTE_DEL_HOST "conf_log_del_remote"
|
||||
#define CONF_LOG_REMOTE_ADD_HOST_FUNC "conf_log_add_remote"
|
||||
#define CONF_LOG_REMOTE_DEL_HOST_FUNC "conf_log_del_remote"
|
||||
#define CONF_LOG_REMOTE_LEVEL_FUNC "conf_log_remote_level"
|
||||
|
||||
typedef struct _level_str {
|
||||
u32 level;
|
||||
|
|
|
@ -144,6 +144,24 @@
|
|||
log_remote_del_host_config_proc, \
|
||||
NULL, \
|
||||
NULL \
|
||||
},\
|
||||
{\
|
||||
LOG_CONFIG_REMOTE_LEVEL, \
|
||||
CONFIG_FROM_WEB, \
|
||||
FALSE, \
|
||||
log_remote_level_config_chk, \
|
||||
log_remote_level_config_proc, \
|
||||
NULL, \
|
||||
NULL \
|
||||
},\
|
||||
{\
|
||||
LOG_CONFIG_FILE, \
|
||||
CONFIG_FROM_WEB, \
|
||||
FALSE, \
|
||||
log_file_config_chk, \
|
||||
log_file_config_proc, \
|
||||
NULL, \
|
||||
NULL \
|
||||
}\
|
||||
}
|
||||
|
||||
|
|
|
@ -28,5 +28,17 @@ ret_code log_remote_add_host_config_proc(uint source, uint config_type,
|
|||
ret_code log_remote_del_host_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
ret_code log_remote_level_config_chk(uint source, uint *config_type,
|
||||
pointer input, int *input_len,
|
||||
pointer output, int *output_len);
|
||||
ret_code log_remote_level_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
ret_code log_file_config_chk(uint source, uint *config_type,
|
||||
pointer input, int *input_len,
|
||||
pointer output, int *output_len);
|
||||
ret_code log_file_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,26 @@
|
|||
#include "log_config.h"
|
||||
#include "log_config_cm.h"
|
||||
|
||||
#define FILE_JSON(s, o) { \
|
||||
s2j_struct_get_basic_element(s, o, int, level); \
|
||||
S2J_STRUCT_GET_STRING_ELEMENT_N(s, o, path, MAX_PATH_SZ); \
|
||||
s2j_struct_get_basic_element(s, o, int, is_compress); \
|
||||
s2j_struct_get_basic_element(s, o, int, del_over_days); \
|
||||
s2j_struct_get_basic_element(s, o, int, del_over_size); \
|
||||
}
|
||||
|
||||
ret_code log_file_config_chk(uint source, uint *config_type,
|
||||
pointer input, int *input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
COMMON_CHK(log_file_t, input, input_len, "file", FILE_JSON);
|
||||
}
|
||||
|
||||
ret_code log_file_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
return log_rpc_exec(SERVICE_LOG_FILE_NAME, CONF_LOG_FILE_FUNC, input, input_len, sizeof(log_file_t));
|
||||
}
|
||||
|
||||
|
|
@ -7,6 +7,11 @@
|
|||
S2J_STRUCT_GET_STRING_ELEMENT_N(s, o, host, LOG_HOST_SZ); \
|
||||
}
|
||||
|
||||
#define REMOTE_LEVEL_JSON(s, o) { \
|
||||
s2j_struct_get_basic_element(s, o, int, level); \
|
||||
}
|
||||
|
||||
|
||||
|
||||
ret_code log_remote_host_config_chk(uint source, uint *config_type,
|
||||
pointer input, int *input_len,
|
||||
|
@ -19,14 +24,28 @@ ret_code log_remote_add_host_config_proc(uint source, uint config_type,
|
|||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
return log_rpc_exec(SERVICE_LOG_REMOTE_NAME, CONF_LOG_REMOTE_ADD_HOST, input, input_len, sizeof(log_remote_host_t));
|
||||
return log_rpc_exec(SERVICE_LOG_REMOTE_NAME, CONF_LOG_REMOTE_ADD_HOST_FUNC, input, input_len, sizeof(log_remote_host_t));
|
||||
}
|
||||
|
||||
ret_code log_remote_del_host_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
return log_rpc_exec(SERVICE_LOG_REMOTE_NAME, CONF_LOG_REMOTE_DEL_HOST, input, input_len, sizeof(log_remote_host_t));
|
||||
return log_rpc_exec(SERVICE_LOG_REMOTE_NAME, CONF_LOG_REMOTE_DEL_HOST_FUNC, input, input_len, sizeof(log_remote_host_t));
|
||||
}
|
||||
|
||||
ret_code log_remote_level_config_chk(uint source, uint *config_type,
|
||||
pointer input, int *input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
COMMON_CHK(log_remote_level_t, input, input_len, "remote level", REMOTE_LEVEL_JSON);
|
||||
}
|
||||
|
||||
ret_code log_remote_level_config_proc(uint source, uint config_type,
|
||||
pointer input, int input_len,
|
||||
pointer output, int *output_len)
|
||||
{
|
||||
return log_rpc_exec(SERVICE_LOG_REMOTE_NAME, CONF_LOG_REMOTE_LEVEL_FUNC, input, input_len, sizeof(log_remote_level_t));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
#include "cmd_file.h"
|
||||
#include "ulog_api.h"
|
||||
#include "log_types.h"
|
||||
#include "logging_common.h"
|
||||
#include "ulog/ulog_in.h"
|
||||
#include "s2j/s2j.h"
|
||||
|
||||
int conf_file(cJSON *json_obj, int argc, char **argv)
|
||||
{
|
||||
log_file_t log_file = {0};
|
||||
log_file.is_compress = LOG_UNCOMPRESS;
|
||||
|
||||
int level = LOG_INFO;
|
||||
if (argc >= 3) {
|
||||
if ((level = log_str_to_level(argv[2])) < 0) {
|
||||
ULOG_WARNING(g_log, "Unknown log level:%s", argv[2]);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
log_file.level = level;
|
||||
|
||||
if (argc >= 4) {
|
||||
strncpy(log_file.path, argv[3], sizeof(log_file.path));
|
||||
}
|
||||
|
||||
if (argc >= 5) {
|
||||
if (atoi(argv[4]) > 0) {
|
||||
log_file.is_compress = LOG_COMPRESS;
|
||||
}
|
||||
}
|
||||
|
||||
if (argc >= 6) {
|
||||
int day = atoi(argv[5]);
|
||||
if (day > 0) {
|
||||
log_file.del_over_days = day;
|
||||
} else if (day < 0) {
|
||||
ULOG_WARNING(g_log, "Deleting day(%d) mustn't be less than 0", day);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (argc >= 7) {
|
||||
int64_t size = atoll(argv[6]);
|
||||
if (size > 0) {
|
||||
log_file.del_over_size = (u64)size;
|
||||
} else if (size < 0) {
|
||||
ULOG_WARNING(g_log, "Deleting size(%d) mustn't be less than 0", size);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
s2j_json_set_basic_element(json_obj, &log_file, int, level);
|
||||
s2j_json_set_basic_element(json_obj, &log_file, string, path);
|
||||
s2j_json_set_basic_element(json_obj, &log_file, int, is_compress);
|
||||
s2j_json_set_basic_element(json_obj, &log_file, int, del_over_days);
|
||||
s2j_json_set_basic_element(json_obj, &log_file, int, del_over_size);
|
||||
|
||||
int ret = set_log_conf(json_obj, LOG_CONFIG_FILE);
|
||||
if (ret != 0) {
|
||||
ULOG_ERR(g_log, "File log which is configured is failure");
|
||||
} else {
|
||||
ULOG_DEBUG(g_log, "File log whice is configured is success");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef _CMD_FILE_H
|
||||
#define _CMD_FILE_H
|
||||
|
||||
#include "cjson/cJSON.h"
|
||||
|
||||
int conf_file(cJSON *json_obj, int argc, char **argv);
|
||||
|
||||
#endif
|
||||
|
|
@ -75,3 +75,31 @@ int conf_remote(cJSON *json_obj, int argc, char **argv)
|
|||
return conf_remote_by_config_id(json_obj, host, port, rfc, config_id);
|
||||
}
|
||||
|
||||
int conf_remote_level(cJSON *json_obj, int argc, char **argv)
|
||||
{
|
||||
if (argc < 3) {
|
||||
ULOG_WARNING(g_log, "Not input log level");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int level;
|
||||
|
||||
if ((level = log_str_to_level(argv[2])) < 0) {
|
||||
ULOG_WARNING(g_log, "Unknown log level:%s", argv[2]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
log_remote_level_t log_level;
|
||||
|
||||
log_level.level = (u8)level;
|
||||
s2j_json_set_basic_element(json_obj, &log_level, int, level);
|
||||
int ret = set_log_conf(json_obj, LOG_CONFIG_REMOTE_LEVEL);
|
||||
if (ret != 0) {
|
||||
ULOG_ERR(g_log, "Remote level of log which is configured is failure");
|
||||
} else {
|
||||
ULOG_DEBUG(g_log, "Remote level of log whice is configured is success");
|
||||
}
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -4,5 +4,6 @@
|
|||
#include "cjson/cJSON.h"
|
||||
|
||||
int conf_remote(cJSON *json_obj, int argc, char **argv);
|
||||
int conf_remote_level(cJSON *json_obj, int argc, char **argv);
|
||||
|
||||
#endif
|
|
@ -3,6 +3,7 @@
|
|||
#include "cmd_console.h"
|
||||
#include "cmd_monitor.h"
|
||||
#include "cmd_remote.h"
|
||||
#include "cmd_file.h"
|
||||
#include "ulog_api.h"
|
||||
#include "s2j/s2j.h"
|
||||
|
||||
|
@ -19,7 +20,9 @@ ulog_t *g_log;
|
|||
log_cmd_t g_log_cmd[] = {
|
||||
{"console", conf_console},
|
||||
{"monitor", conf_monitor},
|
||||
{"host", conf_remote}
|
||||
{"host", conf_remote},
|
||||
{"trap", conf_remote_level},
|
||||
{"file", conf_file}
|
||||
};
|
||||
|
||||
log_cmd_t *get_cb_by_cmd(const char *cmd)
|
||||
|
|
|
@ -206,7 +206,7 @@ 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)
|
||||
int log_off_with_file(const char *path, const char *file_name)
|
||||
{
|
||||
char file[MAX_PATH_SZ];
|
||||
int ret = -1;
|
||||
|
@ -217,9 +217,13 @@ int delete_conf_file(const char *path, const char *file_name)
|
|||
return ret;
|
||||
}
|
||||
if (unlink(file) < 0) {
|
||||
if (errno != ENOENT) {
|
||||
ULOG_ERR(g_log, "Deleting configure file(dir:%s, file:%s) is failure:%s",
|
||||
path, file_name, strerror(errno));
|
||||
return ret;
|
||||
} else {
|
||||
ULOG_DEBUG(g_log, "File(dir:%s, file:%s) is not exist", path, file_name);
|
||||
}
|
||||
}
|
||||
ret = 0;
|
||||
return ret;
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
#define _LOG_COMMON_H
|
||||
|
||||
#include "ulog_api.h"
|
||||
|
||||
#define MAX_LINE_SZ 1024
|
||||
#define MAX_PATH_SZ MAX_LINE_SZ
|
||||
#include "log_types.h"
|
||||
|
||||
#define LOG_CONF_PATH "/etc/rsyslog.d/"
|
||||
|
||||
|
@ -25,7 +23,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);
|
||||
int log_off_with_file(const char *path, const char *file_name);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -58,7 +58,7 @@ static int config_log_console(const log_console_t *conf)
|
|||
switch (conf->on)
|
||||
{
|
||||
case LOG_OFF:
|
||||
ret = delete_conf_file(LOG_CONF_PATH, LOG_CONF_COSOLE_FILE_NAME);
|
||||
ret = log_off_with_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,
|
||||
|
|
|
@ -122,6 +122,7 @@ static int conf_log_file(const log_file_t *conf)
|
|||
if (conf->del_over_size > 0) {
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -135,7 +136,11 @@ void rpc_conf_log_file(rpc_conn *conn, pointer input, int input_len, pointer dat
|
|||
return;
|
||||
}
|
||||
|
||||
conf_log_file((const log_file_t *)input);
|
||||
//rpc_return_null(conn);
|
||||
if (conf_log_file((const log_file_t *)input) != 0) {
|
||||
ULOG_ERR(g_log, "Configuring file of log is faiure");
|
||||
rpc_return_error(conn, RET_ERR, "Configuring file of log is faiure");
|
||||
return;
|
||||
}
|
||||
rpc_return_null(conn);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,21 +7,8 @@
|
|||
#include "common_types.h"
|
||||
#include "rpc_common.h"
|
||||
#include "log_common.h"
|
||||
|
||||
typedef enum {
|
||||
LOG_UNCOMPRESS = 0,
|
||||
LOG_COMPRESS
|
||||
} log_compress_t;
|
||||
|
||||
typedef struct _log_file {
|
||||
u8 level;
|
||||
char path[MAX_PATH_SZ];
|
||||
log_compress_t is_compress;
|
||||
u32 del_over_days;
|
||||
u64 del_over_size;
|
||||
} log_file_t;
|
||||
#include "log_types.h"
|
||||
|
||||
void rpc_conf_log_file(rpc_conn *conn, pointer input, int input_len, pointer data);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -57,7 +57,7 @@ static int config_log_pty(const log_pty_t *conf)
|
|||
switch (conf->on)
|
||||
{
|
||||
case LOG_OFF:
|
||||
ret = delete_conf_file(LOG_CONF_PATH, LOG_CONF_PTY_FILE_NAME);
|
||||
ret = log_off_with_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,
|
||||
|
|
|
@ -375,6 +375,11 @@ void rpc_conf_log_remote_level(rpc_conn *conn, pointer input, int input_len, poi
|
|||
return;
|
||||
}
|
||||
|
||||
config_log_remote_level((const log_remote_level_t *)input);
|
||||
if (config_log_remote_level((const log_remote_level_t *)input) != 0) {
|
||||
ULOG_ERR(g_log, "Configuring remote level of log is faiure");
|
||||
rpc_return_error(conn, RET_ERR, "Configuring remote level of log is faiure");
|
||||
return;
|
||||
}
|
||||
rpc_return_null(conn);
|
||||
}
|
||||
|
||||
|
|
|
@ -84,12 +84,12 @@ int main(int argc, char **argv)
|
|||
ULOG_INFO(g_log, "Server of log schedule is started");
|
||||
|
||||
/* 注册配置处理函数 */
|
||||
rpc_server_regservice(server, SERVICE_LOG_FILE_NAME, "conf_log_file", rpc_conf_log_file);
|
||||
rpc_server_regservice(server, SERVICE_LOG_FILE_NAME, CONF_LOG_FILE_FUNC, 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_FUNC, rpc_conf_log_pty);
|
||||
rpc_server_regservice(server, SERVICE_LOG_REMOTE_NAME, CONF_LOG_REMOTE_ADD_HOST, rpc_conf_log_add_remote);
|
||||
rpc_server_regservice(server, SERVICE_LOG_REMOTE_NAME, CONF_LOG_REMOTE_DEL_HOST, rpc_conf_log_del_remote);
|
||||
rpc_server_regservice(server, SERVICE_LOG_REMOTE_NAME, "conf_log_remote_level", rpc_conf_log_remote_level);
|
||||
rpc_server_regservice(server, SERVICE_LOG_REMOTE_NAME, CONF_LOG_REMOTE_ADD_HOST_FUNC, rpc_conf_log_add_remote);
|
||||
rpc_server_regservice(server, SERVICE_LOG_REMOTE_NAME, CONF_LOG_REMOTE_DEL_HOST_FUNC, rpc_conf_log_del_remote);
|
||||
rpc_server_regservice(server, SERVICE_LOG_REMOTE_NAME, CONF_LOG_REMOTE_LEVEL_FUNC, rpc_conf_log_remote_level);
|
||||
/*
|
||||
|
||||
log_file_t log = {0};
|
||||
|
|
Loading…
Reference in New Issue