diff --git a/Common/log_types.h b/Common/log_types.h new file mode 100755 index 000000000..c3ea4a21a --- /dev/null +++ b/Common/log_types.h @@ -0,0 +1,14 @@ +#ifndef _LOG_CONFIG_API_H +#define _LOG_CONFIG_API_H + +#include "ulog_api.h" + +typedef struct _log_console { + u8 level; + u8 on; + char module_name[MAX_MODULE_NAME_SZ]; +} log_console_t; + +typedef log_console_t log_pty_t; + +#endif \ No newline at end of file diff --git a/Makefile b/Makefile index 5e06bcfb2..936327a05 100755 --- a/Makefile +++ b/Makefile @@ -28,9 +28,9 @@ MAKE_FLAGS += -j$(shell cat /proc/cpuinfo | grep processor | wc -l) endif endif -.PHONY : demo conntrack netlink trace openrpc redismq usermanager configm ulog database webauth khashtable +.PHONY : openrpc ulog demo conntrack netlink trace redismq usermanager configm database webauth khashtable -all: demo conntrack netlink trace openrpc redismq usermanager configm ulog database webauth khashtable +all: openrpc ulog demo conntrack netlink trace redismq usermanager configm database webauth khashtable ifeq ($(OPT), install) #$(shell `find ../release -name "*.zip" -delete`) diff --git a/Platform/build/user.configm.Makefile b/Platform/build/user.configm.Makefile index 52534b784..da676a649 100755 --- a/Platform/build/user.configm.Makefile +++ b/Platform/build/user.configm.Makefile @@ -34,13 +34,14 @@ COMMON_SRCS = configserver.c \ jumppage_config/jumppage.c \ agingtime_config/agingtime.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 + 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 # MRS Board Source Files PLAT_LINUX_SRCS = $(COMMON_SRCS) PLAT_ARM64_SRCS = $(COMMON_SRCS) -COMMOM_CFLAGS = -I../user/configm/config-server/include -I../../Common -I../common/redismq -I../common/configm -I../common/rpc -I../common/rpc/hashtable +COMMOM_CFLAGS = -I../user/configm/config-server/include -I../../Common -I../common/redismq -I../common/configm -I../common/rpc -I../common/rpc/hashtable -I../common/ulog # gcc CFLAGS PLAT_ARM64_CFLAGS := $(COMMOM_CFLAGS) -I../thirdparty/arm64/usr/local/include PLAT_LINUX_CFLAGS := $(COMMOM_CFLAGS) -I../thirdparty/x86_64/usr/local/include @@ -49,10 +50,10 @@ PLAT_ARM64_LDFLAGS := PLAT_LINUX_LDFLAGS := #gcc libs -ARM64_LIBS := ../thirdparty/arm64/libev-arm64.so ./libopenrpc-arm64.so ./libnetlinku-arm64.so ./libredismq-arm64.so +ARM64_LIBS := ../thirdparty/arm64/libev-arm64.so ./libopenrpc-arm64.so ./libnetlinku-arm64.so ./libredismq-arm64.so ./libulogapi-arm64.so ARM64_LIBS += -lpthread -lm -lcjson -levent -ljson-c -lhiredis -LINUX_LIBS := ../thirdparty/x86_64/libev-linux.so ./libopenrpc-linux.so ./libnetlinku-linux.so ./libredismq-linux.so +LINUX_LIBS := ../thirdparty/x86_64/libev-linux.so ./libopenrpc-linux.so ./libnetlinku-linux.so ./libredismq-linux.so ./libulogapi-linux.so LINUX_LIBS += -lpthread -lm -lcjson -levent -ljson-c -lhiredis ifeq ($(PLAT_ARM64), TRUE) diff --git a/Platform/build/user.ulog.log_sched.Makefile b/Platform/build/user.ulog.log_sched.Makefile index 134a94902..f4645297a 100755 --- a/Platform/build/user.ulog.log_sched.Makefile +++ b/Platform/build/user.ulog.log_sched.Makefile @@ -34,7 +34,7 @@ PLAT_LINUX_SRCS = $(COMMON_SRCS) PLAT_ARM64_SRCS = $(COMMON_SRCS) # gcc CFLAGS -PLAT_ARM64_CFLAGS := -fPIC -I../../Common -I../common/rpc -I../user/ulog +PLAT_ARM64_CFLAGS := -fPIC -I../../Common -I../common/rpc -I../common/ulog -I../user/ulog PLAT_LINUX_CFLAGS := $(PLAT_ARM64_CFLAGS) diff --git a/Platform/common/configm/configmapi.h b/Platform/common/configm/configmapi.h old mode 100644 new mode 100755 diff --git a/Platform/common/ulog/ulog_in.h b/Platform/common/ulog/ulog_in.h new file mode 100755 index 000000000..23a6d400b --- /dev/null +++ b/Platform/common/ulog/ulog_in.h @@ -0,0 +1,11 @@ +#ifndef _ULOG_IN_H +#define _ULOG_IN_H + +#define SERVICE_LOG_FILE_NAME "log-file" +#define SERIVCE_LOG_CONSOLE_NAME "log-console" +#define SERVICE_LOG_PTY_NAME "log-pty" +#define SERVICE_LOG_REMOTE_NAME "log-remote" + +#define CONF_LOG_CONSOLE_FUNC "conf_log_console" + +#endif \ No newline at end of file diff --git a/Platform/user/configm/config-server/include/configm.h b/Platform/user/configm/config-server/include/configm.h old mode 100644 new mode 100755 index 5ce54a515..1a93e807e --- a/Platform/user/configm/config-server/include/configm.h +++ b/Platform/user/configm/config-server/include/configm.h @@ -7,6 +7,7 @@ #include "../../../../../Common/commuapinl.h" #include "../user_manager_config/user_group_config.h" #include "../user_manager_config/user_account_config.h" +#include "log_config.h" #include "authfree.h" #include "localportal.h" #include "jumppage.h" @@ -24,6 +25,9 @@ /*PORTAL SERVER CONFIG */ #define LOCALAUTH_CONFIG_MODULE 0x00000003 +#define LOG_CONFIG_MODULE 0x00000004 + + /* config id define*/ #define IPCONFIG_V4 (uint64)((uint64)NETCONFIG_MODULE<<32|1) @@ -37,12 +41,18 @@ #define JUMPPAGE_CONFIG (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|4) #define AGINGTIME_CONFIG (uint64)((uint64)LOCALAUTH_CONFIG_MODULE<<32|5) +#define LOG_CONFIG_CONSOLE (uint64)((uint64)LOG_CONFIG_MODULE<<32|1) + #define CONFIG_INIT_ARRAY \ {\ {\ NETCONFIG_MODULE,\ NULL\ - }\ + },\ + { \ + LOG_CONFIG_MODULE, \ + log_config_init \ + } \ } /* @@ -137,7 +147,17 @@ user_config_proc, \ user_config_get, \ user_config_get_all \ - }\ + },\ + {\ + LOG_CONFIG_CONSOLE, \ + CONFIG_FROM_WEB, \ + FALSE, \ + FALSE, \ + log_console_config_chk, \ + log_console_config_proc, \ + NULL, \ + NULL \ + }\ } typedef ret_code (*cm_config_init)(); diff --git a/Platform/user/configm/config-server/include/log_config.h b/Platform/user/configm/config-server/include/log_config.h new file mode 100755 index 000000000..bf4bd92de --- /dev/null +++ b/Platform/user/configm/config-server/include/log_config.h @@ -0,0 +1,17 @@ +#ifndef _LOG_CONFIG_H +#define _LOG_CONFIG_H + +#include + +#include "rpc_types.h" +#include "rpc_common.h" + +ret_code log_config_init(); +ret_code log_console_config_chk(uint source, uint *config_type, + pointer input, int *input_len, + pointer output, int *output_len); +ret_code log_console_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_console.c b/Platform/user/configm/config-server/log_config/log_config_console.c new file mode 100755 index 000000000..6fd98cebf --- /dev/null +++ b/Platform/user/configm/config-server/log_config/log_config_console.c @@ -0,0 +1,63 @@ +#include + +#include "rpc_server.h" +#include "log_config.h" +#include "configm.h" +#include "log_types.h" +#include "ulog_in.h" +#include "log_config_h.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("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_name, MAX_MODULE_NAME_SZ); + + *input_len = sizeof(*log_console); + memcpy(input, log_console, *input_len); + + return RET_OK; +} + +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; + } + + 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; +} + diff --git a/Platform/user/configm/config-server/log_config/log_config_h.h b/Platform/user/configm/config-server/log_config/log_config_h.h new file mode 100755 index 000000000..33dc5b285 --- /dev/null +++ b/Platform/user/configm/config-server/log_config/log_config_h.h @@ -0,0 +1,7 @@ +#ifndef _LOG_CONFIG_H_H +#define _LOG_CONFIG_H_H + +extern rpc_client *g_log_client; +extern ulog_t *g_log_h; + +#endif \ No newline at end of file diff --git a/Platform/user/configm/config-server/log_config/log_config_init.c b/Platform/user/configm/config-server/log_config/log_config_init.c new file mode 100755 index 000000000..9b4066e5c --- /dev/null +++ b/Platform/user/configm/config-server/log_config/log_config_init.c @@ -0,0 +1,27 @@ +#include "rpc_server.h" +#include "log_config.h" +#include "ulog_in.h" +#include "ulog_api.h" + +rpc_client *g_log_client; +ulog_t *g_log_h; + + +ret_code log_config_init() +{ + g_log_h = ulog_init("log_config", 1); + if (g_log_h) { + fprintf(stderr, "Initiating log_config is failure"); + return RET_ERR; + } + + g_log_client = rpc_client_connect_ex(RPC_MODULE_SYSLOG_NAME); + if (g_log_client == NULL) { + ULOG_ERR(g_log_h, "Initiating rpc client is failure"); + return RET_ERR; + } + + return RET_OK; +} + + diff --git a/Platform/user/ulog/log-sched/log_common.c b/Platform/user/ulog/log-sched/log_common.c index 383cedb09..f6e978fe1 100755 --- a/Platform/user/ulog/log-sched/log_common.c +++ b/Platform/user/ulog/log-sched/log_common.c @@ -124,7 +124,7 @@ int log_conf_append(const u8 level, const char *conf_path, const char *conf_file return __log_conf("a", level, conf_path, conf_file, filter_mod, cb_content, arg); } -int log_level_to_str(const u8 level, char *str, u8 len) +int log_level_to_str(const u8 level, char *str, u32 len) { u8 i; char tmp[20]; diff --git a/Platform/user/ulog/log-sched/log_common.h b/Platform/user/ulog/log-sched/log_common.h index bc789cbbb..885e8f942 100755 --- a/Platform/user/ulog/log-sched/log_common.h +++ b/Platform/user/ulog/log-sched/log_common.h @@ -41,7 +41,7 @@ int log_conf_append(const u8 level, const char *conf_path, const char *conf_file int (*cb_content)(FILE *fp, const u8 level, const char *filter_mod, void *arg), void *arg); 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, u8 len); +int log_level_to_str(const u8 level, char *str, u32 len); #endif diff --git a/Platform/user/ulog/log-sched/log_console.c b/Platform/user/ulog/log-sched/log_console.c index f78eabd90..2635d6542 100755 --- a/Platform/user/ulog/log-sched/log_console.c +++ b/Platform/user/ulog/log-sched/log_console.c @@ -3,6 +3,7 @@ #include #include "log_console.h" +#include "log_types.h" #include "log_common.h" #define LOG_CONF_COSOLE_FILE_NAME "log-console.conf" diff --git a/Platform/user/ulog/log-sched/log_console.h b/Platform/user/ulog/log-sched/log_console.h index f4aac8489..9296cb79f 100755 --- a/Platform/user/ulog/log-sched/log_console.h +++ b/Platform/user/ulog/log-sched/log_console.h @@ -5,12 +5,6 @@ #include "common_types.h" #include "rpc_common.h" -typedef struct _log_console { - u8 level; - u8 on; - char module_name[MAX_MODULE_NAME_SZ]; -} log_console_t; - void rpc_conf_log_console(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 2be07f7d1..5fecc9b68 100755 --- a/Platform/user/ulog/log-sched/log_pty.c +++ b/Platform/user/ulog/log-sched/log_pty.c @@ -4,6 +4,7 @@ #include #include "log_pty.h" +#include "log_types.h" #include "log_common.h" #define LOG_DEV_PTY_DIR LOG_DEV_DIR"pts/" diff --git a/Platform/user/ulog/log-sched/log_pty.h b/Platform/user/ulog/log-sched/log_pty.h index 9a940bb25..8e9d6bfca 100755 --- a/Platform/user/ulog/log-sched/log_pty.h +++ b/Platform/user/ulog/log-sched/log_pty.h @@ -3,8 +3,6 @@ #include "log_console.h" -typedef log_console_t log_pty_t; - void rpc_conf_log_pty(rpc_conn *conn, pointer input, int input_len, pointer data); #endif \ No newline at end of file diff --git a/Platform/user/ulog/log-sched/log_remote.c b/Platform/user/ulog/log-sched/log_remote.c index c4990daca..8be0bdc46 100755 --- a/Platform/user/ulog/log-sched/log_remote.c +++ b/Platform/user/ulog/log-sched/log_remote.c @@ -172,7 +172,7 @@ static int remote_conf_level_content(FILE *fp, const u8 level) ULOG_DEBUG(g_log, "Recover old line:%s to file:%s", rewrite_line, path); n1 = fwrite(rewrite_line, 1, n3, fp); if (n3 != n1) { - ULOG_ERR(g_log, "Recovering old line:%s to file is failure:%s", line, strerror(errno)); + ULOG_ERR(g_log, "Recovering old line:%s to file is failure:%s", rewrite_line, strerror(errno)); goto END; } } diff --git a/Platform/user/ulog/log-sched/log_sched.c b/Platform/user/ulog/log-sched/log_sched.c index d8952a6ba..2094d5eca 100755 --- a/Platform/user/ulog/log-sched/log_sched.c +++ b/Platform/user/ulog/log-sched/log_sched.c @@ -12,15 +12,11 @@ #include "log_pty.h" #include "log_remote.h" #include "rpc_module.h" +#include "ulog_in.h" #define LOG_SCHED_MODULE_NAME "log-sched" -#define SERVICE_LOG_FILE_NAME "log-file" -#define SERIVCE_LOG_CONSOLE_NAME "log-console" -#define SERVICE_LOG_PTY_NAME "log-pty" -#define SERVICE_LOG_REMOTE_NAME "log-remote" - #define DEFAULT_CONFIG_FILE "/etc/log-sched.conf" ulog_t *g_log = NULL; @@ -89,7 +85,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", rpc_conf_log_console); + 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_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);