refactor: 重构日志系统,统一日志接口并添加map工具

This commit is contained in:
2025-10-17 14:55:41 +08:00
parent 9fce78a59e
commit c5c625f50e
10 changed files with 284 additions and 195 deletions

View File

@@ -2,6 +2,8 @@ project(test)
enable_testing()
include_directories(${CMAKE_SOURCE_DIR}/src)
#测试简单基本应用
add_executable(${PROJECT_NAME}simple test-simple.c)
target_link_libraries(${PROJECT_NAME}simple logging)
@@ -17,3 +19,9 @@ add_test(test_file ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}file${CMAKE_EXECUT
add_executable(${PROJECT_NAME}filter test-filter.c)
target_link_libraries(${PROJECT_NAME}filter logging)
add_test(test_filter ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}filter${CMAKE_EXECUTEABLE_SUFFIX})
#测试工具map
add_executable(${PROJECT_NAME}map test-map.c)
target_link_libraries(${PROJECT_NAME}map logging)
add_test(test_map ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}map${CMAKE_EXECUTEABLE_SUFFIX})

View File

@@ -6,8 +6,6 @@
#include <time.h>
int main() {
initDefaultLogger("test-filter", LOG_DEBUG);
Log_info("This is an info message");
Log_error("This is an error message%s", "123");
Log_fatal("This is an fatal message");

View File

@@ -2,7 +2,6 @@
#include "logging/logging-handler.h"
int main() {
initDefaultLogger("testLogger", LOG_DEBUG);
log_Handler *hander = loggingHandlerFile("test_log", 1024 * 1024 * 10);
addHandler(getDefaultLogger(), hander);

17
tests/test-map.c Normal file
View File

@@ -0,0 +1,17 @@
#include "utils/logging-map.h"
int main(int argc, char *argv[]) {
(void)argc;
(void)argv;
Map *map = map_create(0, sizeof(int));
const char *keys[] = {"key1", "key2", "key3", "key4", "key5"};
for (int i = 0; i < 5; i++) {
map_put(map, keys[i], &i);
}
map_destroy(map);
return 0;
}

View File

@@ -1,8 +1,6 @@
#include "logging.h"
int main() {
initDefaultLogger("simple", LOG_DEBUG);
Log_info("This is an info message");
Log_error("This is an error message%s", "123");
Log_fatal("This is an fatal message");