fix 拦截器level参数无效 (#15)
* #feat 增强Fatal级别的底色,修改logging类的方法 * 更新版本号 * 加入test脚本 * fix:conanfile * test action * 修复错别字 * add test on windows action * fix test on windows action * fix action on windows * fix * fix 内存分配错误 * fix msvc 不支持中文注释,删除中文注释 * test on windows and test chinese char * ersion 0.2.4 * feature:根据文件大小分割日志 * fix:内存泄露 * fix:使用char偏移单位 * add english brief * 修改api函数名,加入Default关键字,减除歧义 * Multiple substring interceptors * 更新版本号 * #fix 拦截器对level参数无效 * fix
This commit is contained in:
@@ -24,8 +24,10 @@ static void get_next(char *str, int *next) {
|
||||
}
|
||||
|
||||
static bool kmp_search(char *substr, char *master) {
|
||||
if(substr == NULL)return true; //空串全匹配
|
||||
if(master == NULL)return false;
|
||||
if (substr == NULL)
|
||||
return true; // 空串全匹配
|
||||
if (master == NULL)
|
||||
return false;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int substrlen = strlen(substr);
|
||||
@@ -54,16 +56,19 @@ static bool kmp_search(char *substr, char *master) {
|
||||
}
|
||||
|
||||
static bool _disposeSubstring(log_Interceptor *interceptor,
|
||||
char *level,
|
||||
log_level level,
|
||||
const char *message,
|
||||
...) {
|
||||
int count = 0;
|
||||
keywords_t *keyword = (keywords_t *)(interceptor + 1);
|
||||
|
||||
if (keyword->key == NULL && keyword->next == NULL)
|
||||
if (keyword->key == NULL && keyword->next == NULL) {
|
||||
if (level <= interceptor->level)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
while (keyword != NULL) {
|
||||
while (keyword != NULL && level <= interceptor->level) {
|
||||
if (kmp_search(keyword->key, (char *)message))
|
||||
return true;
|
||||
keyword = keyword->next;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "logging.h"
|
||||
#include "logging/logging-core.h"
|
||||
#include "logging/logging-handler.h"
|
||||
#include "utils/logging-utils.h"
|
||||
#include <stdbool.h>
|
||||
@@ -92,7 +93,10 @@ static void output_to_handler(log_Handler *handler,
|
||||
* @param ... 格式化参数列表
|
||||
* @return
|
||||
*/
|
||||
static void _builtin_cope(char *level, const char *color, const char *message) {
|
||||
static void _builtin_cope(log_level level_e,
|
||||
char *level,
|
||||
const char *color,
|
||||
const char *message) {
|
||||
if (G_LOGGER == NULL) {
|
||||
return;
|
||||
}
|
||||
@@ -104,7 +108,7 @@ static void _builtin_cope(char *level, const char *color, const char *message) {
|
||||
log_Handler *handler = G_LOGGER->handler;
|
||||
|
||||
while (it != NULL) {
|
||||
if (it->_dispose(it, level, message)) {
|
||||
if (it->_dispose(it, level_e, message)) {
|
||||
output_to_handler(it->handler, level, color, message);
|
||||
if (it->jump_out)
|
||||
return;
|
||||
@@ -121,7 +125,7 @@ void log_fatal(const char *message, ...) {
|
||||
va_start(args, message);
|
||||
vsprintf(logStr, message, args);
|
||||
va_end(args);
|
||||
_builtin_cope("Fatal", RED_B, logStr);
|
||||
_builtin_cope(LOG_FATAL, "Fatal", RED_B, logStr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +136,7 @@ void log_error(const char *message, ...) {
|
||||
va_start(args, message);
|
||||
vsprintf(logStr, message, args);
|
||||
va_end(args);
|
||||
_builtin_cope("Error", RED, logStr);
|
||||
_builtin_cope(LOG_ERROR, "Error", RED, logStr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +147,7 @@ void log_warning(const char *message, ...) {
|
||||
va_start(args, message);
|
||||
vsprintf(logStr, message, args);
|
||||
va_end(args);
|
||||
_builtin_cope("Warning", YELLOW, logStr);
|
||||
_builtin_cope(LOG_WARNING, "Warning", YELLOW, logStr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +158,7 @@ void log_info(const char *message, ...) {
|
||||
va_start(args, message);
|
||||
vsprintf(logStr, message, args);
|
||||
va_end(args);
|
||||
_builtin_cope("Info", GREEN, logStr);
|
||||
_builtin_cope(LOG_INFO, "Info", GREEN, logStr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,7 +169,7 @@ void log_debug(const char *message, ...) {
|
||||
va_start(args, message);
|
||||
vsprintf(logStr, message, args);
|
||||
va_end(args);
|
||||
_builtin_cope("Debug", CYAN, logStr);
|
||||
_builtin_cope(LOG_DEBUG, "Debug", CYAN, logStr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user