From 6b6b9e621136c886baffb981aa1973a9d741acc7 Mon Sep 17 00:00:00 2001 From: "Roger.Wang" Date: Tue, 18 Sep 2018 13:36:28 +0800 Subject: [PATCH] Fixed #236 Fixed #234 --- seaslog.c | 7 ++----- src/Analyzer.c | 54 +++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 47 insertions(+), 14 deletions(-) diff --git a/seaslog.c b/seaslog.c index c82c026..0daf14a 100644 --- a/seaslog.c +++ b/seaslog.c @@ -737,7 +737,7 @@ PHP_METHOD(SEASLOG_RES_NAME, analyzerCount) Get log detail by level, log_path, key_word, start, limit, order */ PHP_METHOD(SEASLOG_RES_NAME, analyzerDetail) { - char *level = NULL, *log_path = NULL, *key_word = NULL, *level_template = NULL; + char *level = NULL, *log_path = NULL, *key_word = NULL; int log_path_len = 0, level_len = 0, key_word_len = 0; long start = 1; @@ -815,10 +815,7 @@ PHP_METHOD(SEASLOG_RES_NAME, analyzerDetail) } #endif - seaslog_spprintf(&level_template TSRMLS_CC, SEASLOG_GENERATE_LEVEL_TEMPLATE, level, 0); - - get_detail(log_path, level_template, key_word, start, start + limit - 1, order, return_value TSRMLS_CC); - efree(level_template); + get_detail(log_path, level, key_word, start, start + limit - 1, order, return_value TSRMLS_CC); } /* }}} */ diff --git a/src/Analyzer.c b/src/Analyzer.c index 4f664c7..33a2cd6 100644 --- a/src/Analyzer.c +++ b/src/Analyzer.c @@ -39,7 +39,6 @@ long get_type_count(char *log_path, char *level, char *key_word TSRMLS_DC) else { seaslog_spprintf(&level_template TSRMLS_CC, SEASLOG_GENERATE_LEVEL_TEMPLATE, level, 0); - level = level_template; } @@ -66,7 +65,14 @@ long get_type_count(char *log_path, char *level, char *key_word TSRMLS_DC) if (key_word) { #ifdef WINDOWS - spprintf(&sh, 0, "findstr \"%s\" %s | find /c \"%s\" ", level, path, key_word); + if (is_level_all == 1) + { + spprintf(&sh, 0, "findstr \"%s\" %s ", key_word, path); + } + else + { + spprintf(&sh, 0, "findstr \"%s\" %s | find /c \"%s\" ", level_template, path, key_word); + } #else if (is_level_all == 1) { @@ -74,14 +80,21 @@ long get_type_count(char *log_path, char *level, char *key_word TSRMLS_DC) } else { - spprintf(&sh, 0, "cat %s 2>/dev/null| grep -ai '%s' | grep '%s' -aic", path, level, key_word); + spprintf(&sh, 0, "cat %s 2>/dev/null| grep -ai '%s' | grep '%s' -aic", path, level_template, key_word); } #endif } else { #ifdef WINDOWS - spprintf(&sh, 0, "findstr \"%s\" %s | find /c /v \"\" ", level, path); + if (is_level_all == 1) + { + spprintf(&sh, 0, "findstr %s | find /c /v \"\" ", path); + } + else + { + spprintf(&sh, 0, "findstr \"%s\" %s | find /c /v \"\" ", level_template, path); + } #else if (is_level_all == 1) { @@ -89,7 +102,7 @@ long get_type_count(char *log_path, char *level, char *key_word TSRMLS_DC) } else { - spprintf(&sh, 0, "cat %s 2>/dev/null| grep '%s' -aic", path, level); + spprintf(&sh, 0, "cat %s 2>/dev/null| grep '%s' -aic", path, level_template); } #endif } @@ -126,6 +139,7 @@ int get_detail(char *log_path, char *level, char *key_word, long start, long end char *sh; char *command; int is_level_all = 0; + char *level_template = NULL; memset(buffer, '\0', sizeof(buffer)); @@ -145,6 +159,10 @@ int get_detail(char *log_path, char *level, char *key_word, long start, long end { is_level_all = 1; } + else + { + seaslog_spprintf(&level_template TSRMLS_CC, SEASLOG_GENERATE_LEVEL_TEMPLATE, level, 0); + } if (SEASLOG_G(disting_type)) { @@ -180,7 +198,14 @@ int get_detail(char *log_path, char *level, char *key_word, long start, long end if (key_word && strlen(key_word) >= 1) { #ifdef WINDOWS - spprintf(&sh, 0, "%s \"%s\" %s | %s \"%s\" ", command, level, path, command, key_word); + if (is_level_all == 1) + { + spprintf(&sh, 0, "%s \"%s\" %s ", command, key_word, path); + } + else + { + spprintf(&sh, 0, "%s \"%s\" %s | %s \"%s\" ", command, level_template, path, command, key_word); + } #else if (is_level_all == 1) { @@ -188,14 +213,21 @@ int get_detail(char *log_path, char *level, char *key_word, long start, long end } else { - spprintf(&sh, 0, "%s 2>/dev/null| grep -ai '%s' | grep -ai '%s' | sed -n '%ld,%ld'p", command, level, key_word, start, end); + spprintf(&sh, 0, "%s 2>/dev/null| grep -ai '%s' | grep -ai '%s' | sed -n '%ld,%ld'p", command, level_template, key_word, start, end); } #endif } else { #ifdef WINDOWS - spprintf(&sh, 0, "%s \"%s\" %s", command, level, path); + if (is_level_all == 1) + { + spprintf(&sh, 0, "%s %s", command, path); + } + else + { + spprintf(&sh, 0, "%s \"%s\" %s", command, level_template, path); + } #else if (is_level_all == 1) { @@ -203,7 +235,7 @@ int get_detail(char *log_path, char *level, char *key_word, long start, long end } else { - spprintf(&sh, 0, "%s 2>/dev/null| grep -ai '%s' | sed -n '%ld,%ld'p", command, level, start, end); + spprintf(&sh, 0, "%s 2>/dev/null| grep -ai '%s' | sed -n '%ld,%ld'p", command, level_template, start, end); } #endif } @@ -232,6 +264,10 @@ int get_detail(char *log_path, char *level, char *key_word, long start, long end efree(path); efree(command); efree(sh); + if (level_template) + { + efree(level_template); + } return SUCCESS; }