--- lbbs/src/log.c 2025/11/17 11:17:37 1.34 +++ lbbs/src/log.c 2025/12/18 02:54:16 1.36 @@ -13,6 +13,7 @@ #include "common.h" #include "io.h" #include "log.h" +#include #include #include #include @@ -41,14 +42,14 @@ int log_begin(const char *common_log_fil fp_common_log = fopen(path_common_log, "a"); if (fp_common_log == NULL) { - fprintf(stderr, "fopen(%s) error\n", path_common_log); + fprintf(stderr, "fopen(%s) error: %d\n", path_common_log, errno); return -1; } fp_error_log = fopen(path_error_log, "a"); if (fp_error_log == NULL) { - fprintf(stderr, "fopen(%s) error\n", path_error_log); + fprintf(stderr, "fopen(%s) error: %d\n", path_error_log, errno); return -2; } @@ -78,10 +79,14 @@ inline static void log_head(char *buf, s { snprintf(buf, len, "[%s] [%d] [INFO] ", s_time, getpid()); } - else // if (log_level == LOG_LEVEL_ERROR) + else if (log_level == LOG_LEVEL_ERROR) { snprintf(buf, len, "[%s] [%d] [ERROR] [%s:%d] ", s_time, getpid(), app_file, app_line); } + else // if (log_level == LOG_LEVEL_DEBUG) + { + snprintf(buf, len, "[%s] [%d] [DEBUG] [%s:%d] ", s_time, getpid(), app_file, app_line); + } } int log_printf(enum log_level_t log_level, const char *app_file, int app_line, const char *format, ...) @@ -91,7 +96,7 @@ int log_printf(enum log_level_t log_leve char buf[LINE_BUFFER_LEN]; FILE *fp_log; - fp_log = (log_level == LOG_LEVEL_ERROR ? fp_error_log : fp_common_log); + fp_log = (log_level == LOG_LEVEL_COMMON ? fp_common_log : fp_error_log); log_head(buf, sizeof(buf), log_level, app_file, app_line); strncat(buf, format, sizeof(buf) - strnlen(buf, sizeof(buf))); @@ -126,7 +131,7 @@ int log_restart(void) fp = fopen(path_common_log, "a"); if (fp == NULL) { - log_error("fopen(%s) error\n", path_common_log); + log_error("fopen(%s) error: %d\n", path_common_log, errno); return -1; } fclose(fp_common_log); @@ -138,7 +143,7 @@ int log_restart(void) fp = fopen(path_error_log, "a"); if (fp == NULL) { - log_error("fopen(%s) error\n", path_error_log); + log_error("fopen(%s) error: %d\n", path_error_log, errno); return -2; } fclose(fp_error_log);