2019-08-12 08:56:52 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "cmd_console.h"
|
2019-08-12 10:12:53 +00:00
|
|
|
#include "cmd_monitor.h"
|
2019-08-13 08:25:43 +00:00
|
|
|
#include "cmd_remote.h"
|
2019-08-14 09:17:18 +00:00
|
|
|
#include "cmd_file.h"
|
2019-08-12 08:56:52 +00:00
|
|
|
#include "ulog_api.h"
|
|
|
|
#include "s2j/s2j.h"
|
|
|
|
|
|
|
|
#define LOGGING_MODULE_NAME "logging"
|
|
|
|
|
|
|
|
typedef int (*cmd_cb)(cJSON *, int, char **);
|
|
|
|
|
|
|
|
typedef struct _log_cmd {
|
|
|
|
char cmd[20];
|
|
|
|
cmd_cb cb;
|
|
|
|
} log_cmd_t;
|
|
|
|
|
|
|
|
ulog_t *g_log;
|
2019-08-13 08:25:43 +00:00
|
|
|
log_cmd_t g_log_cmd[] = {
|
2019-08-12 10:12:53 +00:00
|
|
|
{"console", conf_console},
|
2019-08-13 08:25:43 +00:00
|
|
|
{"monitor", conf_monitor},
|
2019-08-14 09:17:18 +00:00
|
|
|
{"host", conf_remote},
|
|
|
|
{"trap", conf_remote_level},
|
|
|
|
{"file", conf_file}
|
2019-08-12 08:56:52 +00:00
|
|
|
};
|
|
|
|
|
2019-08-13 08:25:43 +00:00
|
|
|
log_cmd_t *get_cb_by_cmd(const char *cmd)
|
2019-08-12 08:56:52 +00:00
|
|
|
{
|
2019-08-13 08:25:43 +00:00
|
|
|
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];
|
2019-08-12 08:56:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2019-08-13 08:25:43 +00:00
|
|
|
int ret = -1;
|
2019-08-12 08:56:52 +00:00
|
|
|
if (argc < 2) {
|
|
|
|
fprintf(stdout, "Parameter too few");
|
2019-08-13 08:25:43 +00:00
|
|
|
return ret;
|
2019-08-12 08:56:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_log = ulog_init(LOGGING_MODULE_NAME, 1);
|
|
|
|
if (g_log == NULL) {
|
|
|
|
fprintf(stderr, "Initiating ulog is failure");
|
2019-08-13 08:25:43 +00:00
|
|
|
return ret;
|
2019-08-12 08:56:52 +00:00
|
|
|
}
|
|
|
|
|
2019-08-13 08:25:43 +00:00
|
|
|
log_cmd_t *log_cmd = get_cb_by_cmd(argv[1]);
|
|
|
|
if (log_cmd == NULL) {
|
2019-08-12 08:56:52 +00:00
|
|
|
ULOG_WARNING(g_log, "Not find logging cmd:%s", argv[1]);
|
|
|
|
goto END;
|
|
|
|
}
|
|
|
|
|
|
|
|
s2j_create_json_obj(json_obj);
|
|
|
|
if(json_obj == NULL)
|
|
|
|
{
|
|
|
|
ULOG_ERR(g_log, "Creating json object is failure");
|
|
|
|
goto END;
|
|
|
|
}
|
|
|
|
|
2019-08-13 08:25:43 +00:00
|
|
|
if (log_cmd->cb(json_obj, argc, argv) != 0) {
|
|
|
|
ULOG_ERR(g_log, "Configuring %s is failure", log_cmd->cmd);
|
|
|
|
goto END;
|
|
|
|
}
|
2019-08-12 08:56:52 +00:00
|
|
|
|
2019-08-13 08:25:43 +00:00
|
|
|
ret = 0;
|
2019-08-12 08:56:52 +00:00
|
|
|
END:
|
|
|
|
if(json_obj != NULL) {
|
|
|
|
cJSON_Delete(json_obj);
|
|
|
|
}
|
|
|
|
ulog_close(g_log);
|
2019-08-13 08:25:43 +00:00
|
|
|
return ret;
|
2019-08-12 08:56:52 +00:00
|
|
|
}
|