Add aaa-12 add log cmd monitor
RCA: SOL: 修改人:zhangtao 检视人:
This commit is contained in:
parent
be2edc4649
commit
3f1eebd1af
|
@ -11,7 +11,7 @@ typedef enum {
|
||||||
typedef struct _log_console {
|
typedef struct _log_console {
|
||||||
u8 level;
|
u8 level;
|
||||||
log_sw_t on;
|
log_sw_t on;
|
||||||
char module_name[MAX_MODULE_NAME_SZ];
|
char module[MAX_MODULE_NAME_SZ];
|
||||||
} log_console_t;
|
} log_console_t;
|
||||||
|
|
||||||
typedef log_console_t log_pty_t;
|
typedef log_console_t log_pty_t;
|
||||||
|
|
|
@ -27,7 +27,7 @@ VPATH = ../user/logging
|
||||||
|
|
||||||
# set the source file, don't used .o because of ...
|
# set the source file, don't used .o because of ...
|
||||||
|
|
||||||
COMMON_SRCS = logging_main.c cmd_console.c
|
COMMON_SRCS = logging_main.c cmd_console.c logging_common.c cmd_monitor.c
|
||||||
|
|
||||||
# MRS Board Source Files
|
# MRS Board Source Files
|
||||||
PLAT_LINUX_SRCS = $(COMMON_SRCS)
|
PLAT_LINUX_SRCS = $(COMMON_SRCS)
|
||||||
|
|
|
@ -35,7 +35,7 @@ ret_code log_console_config_chk(uint source, uint *config_type,
|
||||||
|
|
||||||
s2j_struct_get_basic_element(log_console, json_obj, int, level);
|
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_basic_element(log_console, json_obj, int, on);
|
||||||
S2J_STRUCT_GET_STRING_ELEMENT_N(log_console, json_obj, module_name, MAX_MODULE_NAME_SZ);
|
S2J_STRUCT_GET_STRING_ELEMENT_N(log_console, json_obj, module, MAX_MODULE_NAME_SZ);
|
||||||
|
|
||||||
*input_len = sizeof(*log_console);
|
*input_len = sizeof(*log_console);
|
||||||
memcpy(input, log_console, *input_len);
|
memcpy(input, log_console, *input_len);
|
||||||
|
|
|
@ -1,74 +1,11 @@
|
||||||
#include "cmd_console.h"
|
#include "cmd_console.h"
|
||||||
#include "ulog_api.h"
|
#include "ulog_api.h"
|
||||||
#include "log_types.h"
|
#include "log_types.h"
|
||||||
#include "configm.h"
|
|
||||||
#include "configmapi.h"
|
|
||||||
#include "logging_common.h"
|
#include "logging_common.h"
|
||||||
#include "ulog/ulog_in.h"
|
#include "ulog/ulog_in.h"
|
||||||
#include "s2j/s2j.h"
|
#include "s2j/s2j.h"
|
||||||
|
|
||||||
static int __conf_console(cJSON *json_obj, const char *str_level, const log_sw_t on, const char *module_name)
|
|
||||||
{
|
|
||||||
log_console_t console = {0};
|
|
||||||
char *output;
|
|
||||||
int output_len;
|
|
||||||
int ret = -1;
|
|
||||||
u8 level;
|
|
||||||
|
|
||||||
if ((level = log_str_to_level(str_level)) < 0) {
|
|
||||||
ULOG_WARNING(g_log, "Unknown log level:%s", str_level);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.level = level;
|
|
||||||
console.on = on;
|
|
||||||
if (module_name != NULL) {
|
|
||||||
strncpy(console.module_name, module_name, sizeof(console.module_name));
|
|
||||||
}
|
|
||||||
|
|
||||||
s2j_json_set_basic_element(json_obj, &console, int, level);
|
|
||||||
s2j_json_set_basic_element(json_obj, &console, int, on);
|
|
||||||
s2j_json_set_basic_element(json_obj, &console, string, module_name);
|
|
||||||
|
|
||||||
char *json = cJSON_PrintUnformatted(json_obj);
|
|
||||||
if (json == NULL) {
|
|
||||||
ULOG_ERR(g_log, "Converting struct to json is failure");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ULOG_DEBUG(g_log, "Console json is %s", json);
|
|
||||||
ret_code ret_c = web_config_exec_sync(CM_CONFIG_SET, LOG_CONFIG_CONSOLE,
|
|
||||||
json, strlen(json),
|
|
||||||
&output, &output_len);
|
|
||||||
if (ret_c != RET_OK) {
|
|
||||||
ULOG_ERR(g_log, "Console of Web config is failure:%d", ret_c);
|
|
||||||
} else {
|
|
||||||
ret = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (json != NULL) {
|
|
||||||
free(json);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int conf_console(cJSON *json_obj, int argc, char **argv)
|
int conf_console(cJSON *json_obj, int argc, char **argv)
|
||||||
{
|
{
|
||||||
log_sw_t on = LOG_ON;
|
CMD_PARSE_AND_CONFIG_TERMINAL(log_console_t, json_obj, argc, argv, LOG_CONFIG_CONSOLE);
|
||||||
char *level = DEFAULT_LOG_LEVEL;
|
|
||||||
if (argc >= 3) {
|
|
||||||
if (strcasecmp(argv[2], "off") == 0) {
|
|
||||||
on = LOG_OFF;
|
|
||||||
} else {
|
|
||||||
level = argv[2];
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
char *module = NULL;
|
|
||||||
if (argc >= 4) {
|
|
||||||
module = argv[3];
|
|
||||||
}
|
|
||||||
|
|
||||||
return __conf_console(json_obj, level, on, module);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
#include "cmd_console.h"
|
||||||
|
#include "ulog_api.h"
|
||||||
|
#include "log_types.h"
|
||||||
|
#include "logging_common.h"
|
||||||
|
#include "ulog/ulog_in.h"
|
||||||
|
#include "s2j/s2j.h"
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
#ifndef _CMD_MONITOR_H
|
||||||
|
#define _CMD_MONITOR_H
|
||||||
|
|
||||||
|
#include "cjson/cJSON.h"
|
||||||
|
|
||||||
|
//int conf_console(cJSON *json_obj, const char *str_level, const char *module_name);
|
||||||
|
int conf_monitor(cJSON *json_obj, int argc, char **argv);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
#include "logging_common.h"
|
||||||
|
#include "ulog_api.h"
|
||||||
|
#include "log_types.h"
|
||||||
|
#include "configm.h"
|
||||||
|
#include "configmapi.h"
|
||||||
|
#include "ulog/ulog_in.h"
|
||||||
|
|
||||||
|
int set_log_conf(cJSON *json_obj, uint64 config_id)
|
||||||
|
{
|
||||||
|
int ret = -1;
|
||||||
|
char *output;
|
||||||
|
int output_len;
|
||||||
|
|
||||||
|
char *json = cJSON_PrintUnformatted(json_obj);
|
||||||
|
if (json == NULL) {
|
||||||
|
ULOG_ERR(g_log, "Converting struct to json is failure");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
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*/,
|
||||||
|
json, strlen(json),
|
||||||
|
&output, &output_len);
|
||||||
|
if (ret_c != RET_OK) {
|
||||||
|
ULOG_ERR(g_log, "Log of Web config is failure:%d", ret_c);
|
||||||
|
} else {
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json != NULL) {
|
||||||
|
free(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
|
@ -1,8 +1,66 @@
|
||||||
#ifndef _LOGGING_COMMON_H
|
#ifndef _LOGGING_COMMON_H
|
||||||
#define _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"
|
#define DEFAULT_LOG_LEVEL "info"
|
||||||
|
|
||||||
extern ulog_t *g_log;
|
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}; \
|
||||||
|
u8 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.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 configure of log is failure"); \
|
||||||
|
} \
|
||||||
|
ULOG_DEBUG(g_log, "Setting 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
|
#endif
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "cmd_console.h"
|
#include "cmd_console.h"
|
||||||
|
#include "cmd_monitor.h"
|
||||||
#include "ulog_api.h"
|
#include "ulog_api.h"
|
||||||
#include "s2j/s2j.h"
|
#include "s2j/s2j.h"
|
||||||
|
|
||||||
|
@ -15,7 +16,8 @@ typedef struct _log_cmd {
|
||||||
|
|
||||||
ulog_t *g_log;
|
ulog_t *g_log;
|
||||||
log_cmd_t log_cmd[] = {
|
log_cmd_t log_cmd[] = {
|
||||||
{"console", conf_console}
|
{"console", conf_console},
|
||||||
|
{"monitor", conf_monitor}
|
||||||
};
|
};
|
||||||
|
|
||||||
cmd_cb get_cb_by_cmd(const char *cmd)
|
cmd_cb get_cb_by_cmd(const char *cmd)
|
||||||
|
|
|
@ -74,7 +74,7 @@ static int config_log_console(const log_console_t *conf)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case LOG_ON:
|
case LOG_ON:
|
||||||
if (log_conf(conf->level, LOG_CONF_PATH, LOG_CONF_COSOLE_FILE_NAME, conf->module_name,
|
if (log_conf(conf->level, LOG_CONF_PATH, LOG_CONF_COSOLE_FILE_NAME, conf->module,
|
||||||
write_console_content, NULL) != 0) {
|
write_console_content, NULL) != 0) {
|
||||||
ULOG_ERR(g_log, "Log's console configure which is written is failure");
|
ULOG_ERR(g_log, "Log's console configure which is written is failure");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
@ -84,7 +84,7 @@ static int config_log_console(const log_console_t *conf)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rpc_conf_log_console(rpc_conn *conn, pointer input, int input_len, pointer data)
|
void rpc_conf_log_console(rpc_conn *conn, pointer input, int input_len, pointer data)
|
||||||
|
|
|
@ -52,7 +52,7 @@ 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)
|
static int config_log_pty(const log_pty_t *conf)
|
||||||
{
|
{
|
||||||
if (log_conf(conf->level, LOG_CONF_PATH, LOG_CONF_PTY_FILE_NAME, conf->module_name,
|
if (log_conf(conf->level, LOG_CONF_PATH, LOG_CONF_PTY_FILE_NAME, conf->module,
|
||||||
write_pty_content, NULL) != 0) {
|
write_pty_content, NULL) != 0) {
|
||||||
ULOG_ERR(g_log, "Log's pty configure which is written is failure");
|
ULOG_ERR(g_log, "Log's pty configure which is written is failure");
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Reference in New Issue