diff --git a/include/logging/logging-handler.h b/include/logging/logging-handler.h index fe7d169..2be8f46 100644 --- a/include/logging/logging-handler.h +++ b/include/logging/logging-handler.h @@ -12,6 +12,6 @@ typedef struct log_Handler { log_Handler* fileHandler(const char* name); -log_Handler* consoleHandler(const char* name); +log_Handler* consoleHandler(); #endif //__LOGGING_HANDLER_H__ \ No newline at end of file diff --git a/src/handler/logging-handler-console.c b/src/handler/logging-handler-console.c index a646f30..7435784 100644 --- a/src/handler/logging-handler-console.c +++ b/src/handler/logging-handler-console.c @@ -7,24 +7,25 @@ #include /** - * @description 释放组件 - * @param + * @brief 释放组件 + * @param handler 处理器 */ static void __freeConsoleHandler(log_Handler *handler) { free(handler); } /** - * @description 输出组件 - * @param + * @brief 输出组件 + * @param handler 处理器 + * @param message 消息 */ static void outputConsoleHandler(log_Handler *handler, const char *message) { fputs(message, handler->stream); } /** - * @description :控制台日志处理器 + * @brief :控制台日志处理器 * @param */ -log_Handler *consoleHandler(const char *name) { +log_Handler *consoleHandler() { log_Handler *handler = (log_Handler *)malloc(sizeof(log_Handler)); handler->stream = stdout; diff --git a/src/handler/logging-handler-file.c b/src/handler/logging-handler-file.c index 06e7ece..c06b994 100644 --- a/src/handler/logging-handler-file.c +++ b/src/handler/logging-handler-file.c @@ -7,7 +7,7 @@ #include /** - * @description :文件日志处理器释放组件 + * @brief 文件日志处理器释放组件 * @param * @return */ @@ -17,7 +17,7 @@ static void __freeFileHandler(log_Handler *handler) { } /** - * @description :文件日志处理器输出组件 + * @brief 文件日志处理器输出组件 * @param * @return */ @@ -26,13 +26,14 @@ static void outputFileHandler(log_Handler *handler, const char *message) { } /** - * @description :文件日志处理器 + * @brief 文件日志处理器 * @param * @return */ log_Handler *fileHandler(const char *name) { char new_file_name[100]; sprintf(new_file_name, "%s.log", name); + FILE *fp = fopen(new_file_name, "at"); log_Handler *handler = (log_Handler *)malloc(sizeof(log_Handler)); diff --git a/src/logging.c b/src/logging.c index d1e8d7f..92d2991 100644 --- a/src/logging.c +++ b/src/logging.c @@ -4,6 +4,7 @@ ********************************************/ #include "logging.h" +#include "logging/logging-handler.h" #include #include #include @@ -49,10 +50,10 @@ static void addHandler(log_Handler *handler) { } /** -* @description : 添加日志拦截器 -* @param -* @return -*/ + * @description : 添加日志拦截器 + * @param + * @return + */ void addInterceptor(log_Interceptor *Interceptor) { if (G_LOGGER == NULL) { return; @@ -169,6 +170,7 @@ static Logger *getLogger(const char *name, log_level level) { if (G_LOGGER != NULL) { return G_LOGGER; } + Logger *logger = (Logger *)malloc(sizeof(Logger)); logger->fatal = fatal; logger->error = error; @@ -180,7 +182,7 @@ static Logger *getLogger(const char *name, log_level level) { logger->addInterceptor = addInterceptor; logger->level = level; - logger->handler = NULL; + logger->handler = consoleHandler(name); logger->name = name; logger->interceptor = NULL; diff --git a/tests/test_interceptor.c b/tests/test_interceptor.c index 7137bbe..67a1b0d 100644 --- a/tests/test_interceptor.c +++ b/tests/test_interceptor.c @@ -4,7 +4,6 @@ int main() { Logging *log = createLogging(); Logger *logger = log->getLogger("testLogger", LOG_DEBUG); - logger->addHandler(consoleHandler("test")); logger->info("This is an info message"); logger->error("你好,这是一个错误消息%s", "123"); @@ -22,7 +21,6 @@ int main() { logger->info("This is an info message"); logger->error("你好,这是一个错误消息%s", "123"); logger->fatal("This is an fatal message"); - logger->debug("This is a debug message"); logger->warning("This is a warning message%s", "123"); diff --git a/tests/test_simple.c b/tests/test_simple.c index 9d5aaf7..0646b12 100644 --- a/tests/test_simple.c +++ b/tests/test_simple.c @@ -4,13 +4,13 @@ int main() { Logging *log = createLogging(); Logger *logger = log->getLogger("testLogger",LOG_DEBUG); - logger->addHandler(consoleHandler("test")); - + logger->info("This is an info message"); logger->error("你好,这是一个错误消息%s", "123"); logger->fatal("This is an fatal message"); logger->debug("This is a debug message"); logger->warning("This is a warning message%s", "123"); + destroyLogging(log); return 0;