feat: 优化日志系统,添加日志器缓存机制
This commit is contained in:
@@ -20,6 +20,10 @@ 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})
|
||||
|
||||
#测试多log多次获取
|
||||
add_executable(${PROJECT_NAME}logs test-logs.c)
|
||||
target_link_libraries(${PROJECT_NAME}logs logging)
|
||||
add_test(test_logs ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}logs${CMAKE_EXECUTEABLE_SUFFIX})
|
||||
|
||||
#测试工具map
|
||||
add_executable(${PROJECT_NAME}map test-map.c)
|
||||
|
||||
24
tests/test-logs.c
Normal file
24
tests/test-logs.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "logging.h"
|
||||
#include "logging/logging-core.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
Logger *t1 = getLogger("Test1");
|
||||
t1->level = LOG_ERROR;
|
||||
|
||||
Logger *t2 = getLogger("Test2");
|
||||
t2->level = LOG_DEBUG;
|
||||
|
||||
Logger *t11 = getLogger("Test1");
|
||||
|
||||
if (t1 == t11) {
|
||||
printf("t1 and t11 are the same\n");
|
||||
printf("t1 log level: %s", LOG_LEVEL_STR[t11->level]);
|
||||
} else {
|
||||
printf("t1 and t11 are different\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
destroyDefaultLogger();
|
||||
return 0;
|
||||
}
|
||||
@@ -1,17 +1,37 @@
|
||||
#include "utils/logging-map.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void foreach_callback(const char *key, void *value, void *user_data) {
|
||||
(void)user_data;
|
||||
printf("foreach key: %s, value: %d\n", key, *(int *)value);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
Map *map = map_create(0, sizeof(int));
|
||||
Map *map = map_create(sizeof(int));
|
||||
|
||||
const char *keys[] = {"key1", "key2", "key3", "key4", "key5"};
|
||||
const char *keys[] = {"key1", "key22", "key33", "key44", "key55"};
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
printf("put key %s,value %d\n", keys[i], i);
|
||||
map_put(map, keys[i], &i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
int *value = map_get(map, keys[i]);
|
||||
printf("get value: %d\n", *value);
|
||||
if (*value != i) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
map_foreach(map, foreach_callback, NULL);
|
||||
|
||||
map_destroy(map);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user