Skip to content

Commit

Permalink
Fixed #236 Fixed #234
Browse files Browse the repository at this point in the history
  • Loading branch information
aiwhj committed Sep 18, 2018
1 parent fe0c9fa commit 6b6b9e6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 14 deletions.
7 changes: 2 additions & 5 deletions seaslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
/* }}} */

Expand Down
54 changes: 45 additions & 9 deletions src/Analyzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand All @@ -66,30 +65,44 @@ 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)
{
spprintf(&sh, 0, "cat %s 2>/dev/null| grep '%s' -aic", path, key_word);
}
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)
{
spprintf(&sh, 0, "cat %s 2>/dev/null| wc -l", path);
}
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
}
Expand Down Expand Up @@ -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));

Expand All @@ -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))
{
Expand Down Expand Up @@ -180,30 +198,44 @@ 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)
{
spprintf(&sh, 0, "%s 2>/dev/null| grep -ai '%s' | sed -n '%ld,%ld'p", command, key_word, start, 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)
{
spprintf(&sh, 0, "%s 2>/dev/null| sed -n '%ld,%ld'p", command, start, 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
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 6b6b9e6

Please sign in to comment.