diff --git a/Common/config_manager.h b/Common/config_manager.h old mode 100644 new mode 100755 index 5be7b2c88..99878b6da --- a/Common/config_manager.h +++ b/Common/config_manager.h @@ -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) diff --git a/Common/log_types.h b/Common/log_types.h index e30c12778..d3d0d7b98 100755 --- a/Common/log_types.h +++ b/Common/log_types.h @@ -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 diff --git a/Platform/build/user.configm.Makefile b/Platform/build/user.configm.Makefile index 1e119b0d4..930f98073 100755 --- a/Platform/build/user.configm.Makefile +++ b/Platform/build/user.configm.Makefile @@ -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) diff --git a/Platform/build/user.logging.Makefile b/Platform/build/user.logging.Makefile index c70c42e8b..72ac3917c 100755 --- a/Platform/build/user.logging.Makefile +++ b/Platform/build/user.logging.Makefile @@ -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) diff --git a/Platform/common/ulog/ulog_in.h b/Platform/common/ulog/ulog_in.h index f63dbf766..b24fa1203 100755 --- a/Platform/common/ulog/ulog_in.h +++ b/Platform/common/ulog/ulog_in.h @@ -11,10 +11,12 @@ #define SERVICE_LOG_PTY_NAME "log-pty" #define SERVICE_LOG_REMOTE_NAME "log-remote" -#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_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_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; diff --git a/Platform/user/configm/config-server/include/configm.h b/Platform/user/configm/config-server/include/configm.h index a7aa72c65..6d0ce19a0 100755 --- a/Platform/user/configm/config-server/include/configm.h +++ b/Platform/user/configm/config-server/include/configm.h @@ -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 \ }\ } diff --git a/Platform/user/configm/config-server/include/log_config.h b/Platform/user/configm/config-server/include/log_config.h index 81830c995..047246bbf 100755 --- a/Platform/user/configm/config-server/include/log_config.h +++ b/Platform/user/configm/config-server/include/log_config.h @@ -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 \ No newline at end of file diff --git a/Platform/user/configm/config-server/log_config/log_config_file.c b/Platform/user/configm/config-server/log_config/log_config_file.c new file mode 100755 index 000000000..9f7d7dd96 --- /dev/null +++ b/Platform/user/configm/config-server/log_config/log_config_file.c @@ -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)); +} + + diff --git a/Platform/user/configm/config-server/log_config/log_config_remote.c b/Platform/user/configm/config-server/log_config/log_config_remote.c index da61bdefb..66c9d7b6b 100755 --- a/Platform/user/configm/config-server/log_config/log_config_remote.c +++ b/Platform/user/configm/config-server/log_config/log_config_remote.c @@ -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)); } diff --git a/Platform/user/logging/cmd_file.c b/Platform/user/logging/cmd_file.c new file mode 100755 index 000000000..fefae2aba --- /dev/null +++ b/Platform/user/logging/cmd_file.c @@ -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; +} + diff --git a/Platform/user/logging/cmd_file.h b/Platform/user/logging/cmd_file.h new file mode 100755 index 000000000..551350b7b --- /dev/null +++ b/Platform/user/logging/cmd_file.h @@ -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 + diff --git a/Platform/user/logging/cmd_remote.c b/Platform/user/logging/cmd_remote.c index dfb037559..656a9dc20 100755 --- a/Platform/user/logging/cmd_remote.c +++ b/Platform/user/logging/cmd_remote.c @@ -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; + +} + diff --git a/Platform/user/logging/cmd_remote.h b/Platform/user/logging/cmd_remote.h index 60803c816..fd7ec0254 100755 --- a/Platform/user/logging/cmd_remote.h +++ b/Platform/user/logging/cmd_remote.h @@ -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 \ No newline at end of file diff --git a/Platform/user/logging/logging_main.c b/Platform/user/logging/logging_main.c index 13af2407c..d5379dd3f 100755 --- a/Platform/user/logging/logging_main.c +++ b/Platform/user/logging/logging_main.c @@ -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) diff --git a/Platform/user/ulog/log-sched/log_common.c b/Platform/user/ulog/log-sched/log_common.c index f2d4f5fc3..13497b32d 100755 --- a/Platform/user/ulog/log-sched/log_common.c +++ b/Platform/user/ulog/log-sched/log_common.c @@ -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) { - ULOG_ERR(g_log, "Deleting configure file(dir:%s, file:%s) is failure:%s", + if (errno != ENOENT) { + ULOG_ERR(g_log, "Deleting configure file(dir:%s, file:%s) is failure:%s", path, file_name, strerror(errno)); - return ret; + return ret; + } else { + ULOG_DEBUG(g_log, "File(dir:%s, file:%s) is not exist", path, file_name); + } } ret = 0; return ret; diff --git a/Platform/user/ulog/log-sched/log_common.h b/Platform/user/ulog/log-sched/log_common.h index 9b6e70bc7..5da604737 100755 --- a/Platform/user/ulog/log-sched/log_common.h +++ b/Platform/user/ulog/log-sched/log_common.h @@ -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 diff --git a/Platform/user/ulog/log-sched/log_console.c b/Platform/user/ulog/log-sched/log_console.c index 8caad9e2a..8ba817721 100755 --- a/Platform/user/ulog/log-sched/log_console.c +++ b/Platform/user/ulog/log-sched/log_console.c @@ -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, diff --git a/Platform/user/ulog/log-sched/log_file.c b/Platform/user/ulog/log-sched/log_file.c index 8be02d471..777dc0039 100755 --- a/Platform/user/ulog/log-sched/log_file.c +++ b/Platform/user/ulog/log-sched/log_file.c @@ -121,7 +121,8 @@ 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); } diff --git a/Platform/user/ulog/log-sched/log_file.h b/Platform/user/ulog/log-sched/log_file.h index e6d8120ef..0fd9b5d73 100755 --- a/Platform/user/ulog/log-sched/log_file.h +++ b/Platform/user/ulog/log-sched/log_file.h @@ -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 diff --git a/Platform/user/ulog/log-sched/log_pty.c b/Platform/user/ulog/log-sched/log_pty.c index 18d94b93b..2b03f1dfc 100755 --- a/Platform/user/ulog/log-sched/log_pty.c +++ b/Platform/user/ulog/log-sched/log_pty.c @@ -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, diff --git a/Platform/user/ulog/log-sched/log_remote.c b/Platform/user/ulog/log-sched/log_remote.c index 4a42e8e33..98d7b0204 100755 --- a/Platform/user/ulog/log-sched/log_remote.c +++ b/Platform/user/ulog/log-sched/log_remote.c @@ -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); } diff --git a/Platform/user/ulog/log-sched/log_sched.c b/Platform/user/ulog/log-sched/log_sched.c index d7a5660c6..8d9f4f88d 100755 --- a/Platform/user/ulog/log-sched/log_sched.c +++ b/Platform/user/ulog/log-sched/log_sched.c @@ -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};