提交 0ea3d485 authored 作者: Mathieu Rene's avatar Mathieu Rene

Add /uuid command to fs_cli to filter logs by uuid

上级 360e8aae
...@@ -76,6 +76,7 @@ static int process_command(esl_handle_t *handle, const char *cmd); ...@@ -76,6 +76,7 @@ static int process_command(esl_handle_t *handle, const char *cmd);
static int running = 1; static int running = 1;
static int thread_running = 0; static int thread_running = 0;
static char *filter_uuid;
/* /*
...@@ -588,26 +589,28 @@ static void *msg_thread_run(esl_thread_t *me, void *obj) ...@@ -588,26 +589,28 @@ static void *msg_thread_run(esl_thread_t *me, void *obj)
if (!esl_strlen_zero(type)) { if (!esl_strlen_zero(type)) {
if (!strcasecmp(type, "log/data")) { if (!strcasecmp(type, "log/data")) {
int level = 0; const char *userdata = esl_event_get_header(handle->last_event, "user-data");
const char *lname = esl_event_get_header(handle->last_event, "log-level");
#ifdef WIN32
DWORD len = (DWORD) strlen(handle->last_event->body);
DWORD outbytes = 0;
#endif
if (lname) {
level = atoi(lname);
}
if (esl_strlen_zero(userdata) || esl_strlen_zero(filter_uuid) || !strcasecmp(filter_uuid, userdata)) {
int level = 0;
const char *lname = esl_event_get_header(handle->last_event, "log-level");
#ifdef WIN32
DWORD len = (DWORD) strlen(handle->last_event->body);
DWORD outbytes = 0;
#endif
if (lname) {
level = atoi(lname);
}
#ifdef WIN32
SetConsoleTextAttribute(hStdout, COLORS[level]); #ifdef WIN32
WriteFile(hStdout, handle->last_event->body, len, &outbytes, NULL); SetConsoleTextAttribute(hStdout, COLORS[level]);
SetConsoleTextAttribute(hStdout, wOldColorAttrs); WriteFile(hStdout, handle->last_event->body, len, &outbytes, NULL);
#else SetConsoleTextAttribute(hStdout, wOldColorAttrs);
printf("%s%s%s", COLORS[level], handle->last_event->body, ESL_SEQ_DEFAULT_COLOR); #else
#endif printf("%s%s%s", COLORS[level], handle->last_event->body, ESL_SEQ_DEFAULT_COLOR);
#endif
}
known++; known++;
} else if (!strcasecmp(type, "text/disconnect-notice")) { } else if (!strcasecmp(type, "text/disconnect-notice")) {
running = thread_running = 0; running = thread_running = 0;
...@@ -669,9 +672,22 @@ static int process_command(esl_handle_t *handle, const char *cmd) ...@@ -669,9 +672,22 @@ static int process_command(esl_handle_t *handle, const char *cmd)
) { ) {
esl_log(ESL_LOG_INFO, "Goodbye!\nSee you at ClueCon http://www.cluecon.com/\n"); esl_log(ESL_LOG_INFO, "Goodbye!\nSee you at ClueCon http://www.cluecon.com/\n");
return -1; return -1;
} } else if (!strncasecmp(cmd, "uuid", 4)) {
cmd += 4;
while (*cmd && *cmd == ' ') {
cmd++;
}
if ( if (!esl_strlen_zero(cmd)) {
filter_uuid = strdup(cmd);
} else {
esl_safe_free(filter_uuid);
}
printf("UUID filtering %s\n", filter_uuid ? "enabled" : "disabled");
} else if (
!strncasecmp(cmd, "event", 5) || !strncasecmp(cmd, "event", 5) ||
!strncasecmp(cmd, "noevent", 7) || !strncasecmp(cmd, "noevent", 7) ||
!strncasecmp(cmd, "nixevent", 8) || !strncasecmp(cmd, "nixevent", 8) ||
...@@ -683,11 +699,7 @@ static int process_command(esl_handle_t *handle, const char *cmd) ...@@ -683,11 +699,7 @@ static int process_command(esl_handle_t *handle, const char *cmd)
esl_send_recv(handle, cmd); esl_send_recv(handle, cmd);
printf("%s\n", handle->last_sr_reply); printf("%s\n", handle->last_sr_reply);
} else if (!strncasecmp(cmd, "debug", 5)){
goto end;
}
if (!strncasecmp(cmd, "debug", 5)){
int tmp_debug = atoi(cmd+6); int tmp_debug = atoi(cmd+6);
if (tmp_debug > -1 && tmp_debug < 8){ if (tmp_debug > -1 && tmp_debug < 8){
esl_global_set_default_logger(tmp_debug); esl_global_set_default_logger(tmp_debug);
...@@ -695,10 +707,9 @@ static int process_command(esl_handle_t *handle, const char *cmd) ...@@ -695,10 +707,9 @@ static int process_command(esl_handle_t *handle, const char *cmd)
} else { } else {
printf("fs_cli debug level must be 0 - 7\n"); printf("fs_cli debug level must be 0 - 7\n");
} }
goto end; } else {
printf("Unknown command [%s]\n", cmd);
} }
printf("Unknown command [%s]\n", cmd);
} else { } else {
char cmd_str[1024] = ""; char cmd_str[1024] = "";
const char *err = NULL; const char *err = NULL;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论