diff --git a/TC1/http_server/web_log.c b/TC1/http_server/web_log.c index ddd72bf..5d4e759 100644 --- a/TC1/http_server/web_log.c +++ b/TC1/http_server/web_log.c @@ -7,6 +7,7 @@ LogRecord log_record = { 1,{ 0 } }; char log_record_str[LOG_NUM*LOG_LEN] = { 0 }; char* LOG_TMP; +char log[LOG_LEN]; time_t now; char time_buf[TIM_LEN]; @@ -39,3 +40,19 @@ char* GetLogRecord() return log_record_str; } +void web_log(const char *N, const char *M, ...) +{ + va_list ap; + va_start(ap, M); + int ret = vsnprintf(log, sizeof(log), M, ap); + va_end(ap); + puts(msg); + + LOG_TMP = (char*)malloc(sizeof(char)*LOG_LEN); + now = time(NULL); + now += 28800; + strftime(time_buf, TIM_LEN, "%Y-%m-%d %H:%M:%S", localtime(&now)); + snprintf(LOG_TMP, LOG_LEN, "[%s][%s %s:%d] %s", time_buf, N, SHORT_FILE, __LINE__, log); + SetLogRecord(&log_record, LOG_TMP); +} + diff --git a/TC1/http_server/web_log.h b/TC1/http_server/web_log.h index fcb37c1..605183c 100644 --- a/TC1/http_server/web_log.h +++ b/TC1/http_server/web_log.h @@ -20,8 +20,9 @@ extern char time_buf[]; void SetLogRecord(LogRecord* lr, char* log); char* GetLogRecord(); +void web_log(const char *N, const char *M, ...); -#define web_log(N, M, ...) \ +#define web_log0(N, M, ...) \ LOG_TMP = (char*)malloc(sizeof(char)*LOG_LEN); \ now = time(NULL); \ now += 28800; \