#将拦截器改名为过滤器,更加接近职能

This commit is contained in:
2024-11-23 08:08:21 +08:00
parent 9b777e4862
commit 1c09c41ea3
16 changed files with 166 additions and 160 deletions

View File

@@ -3,7 +3,7 @@ project(test)
enable_testing()
#测试简单基本应用
add_executable(${PROJECT_NAME}simple test_simple.c)
add_executable(${PROJECT_NAME}simple test-simple.c)
target_link_libraries(${PROJECT_NAME}simple logging)
if(UNIX)
add_test(test_simple ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}simple)
@@ -12,10 +12,10 @@ elseif(WIN32)
endif()
#测试拦截器
add_executable(${PROJECT_NAME}interceptor test_interceptor.c)
target_link_libraries(${PROJECT_NAME}interceptor logging)
add_executable(${PROJECT_NAME}filter test-filter.c)
target_link_libraries(${PROJECT_NAME}filter logging)
if(UNIX)
add_test(test_interceptor ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}interceptor)
add_test(test_filter ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}filter)
elseif(WIN32)
add_test(test_interceptor ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}interceptor.exe)
add_test(test_filter ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}filter.exe)
endif()

View File

@@ -1,5 +1,6 @@
#include "logging.h"
#include "logging/logging-core.h"
#include "logging/logging-filter.h"
#include <stdbool.h>
#include <stdio.h>
#include <time.h>
@@ -13,28 +14,28 @@ int main() {
log_debug("This is a debug message");
log_warning("This is a warning message%s", "123");
char *test1[] = {"This", NULL};
char *test1[] = {"This", NULL};
log_Interceptor *tint = loggingSubStringInterceptor(
test1,
LOG_DEBUG,
loggingFileHandler("test_interceptor", 1024 * 1024),
false);
log_filter *tint =
loggingFilterSubStr(test1,
LOG_DEBUG,
loggingHandlerFile("test_interceptor", 1024 * 1024),
false);
logger->addInterceptor(tint);
logger->addFilter(tint);
char *test2[] = {"123", NULL};
char *test2[] = {"123", NULL};
log_Interceptor *tint1 = loggingSubStringInterceptor(
log_filter *tint1 = loggingFilterSubStr(
test2,
LOG_ERROR,
loggingFileHandler("test_interceptor1", 1024 * 1024),
loggingHandlerFile("test_interceptor1", 1024 * 1024),
true);
logger->addInterceptor(tint1);
logger->addFilter(tint1);
printf("\n");
printf("Interceptor added\n");
printf("filter added\n");
printf("\n");
log_info("This is an info message");