From e1e00b60ce12bc7ac31c5821e4f1b153fb747688 Mon Sep 17 00:00:00 2001 From: zogodo <742782908@qq.com> Date: Sun, 10 Apr 2022 15:28:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96web=5Flog=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TC1/http_server/web_log.c | 4 +--- TC1/http_server/web_log.h | 12 +++++------- TC1/main.h | 20 ++++++++++---------- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/TC1/http_server/web_log.c b/TC1/http_server/web_log.c index f4c0234..98260b6 100644 --- a/TC1/http_server/web_log.c +++ b/TC1/http_server/web_log.c @@ -6,9 +6,7 @@ #include"http_server/web_log.h" char* LOG_TMP; -//char log[LOG_LEN]; -time_t now; -char time_buf[TIM_LEN]; +time_t LOG_NOW; LogRecord log_record = { 1,{ 0 } }; char log_record_str[LOG_NUM*LOG_LEN] = { 0 }; diff --git a/TC1/http_server/web_log.h b/TC1/http_server/web_log.h index 3bb107d..fe5cc50 100644 --- a/TC1/http_server/web_log.h +++ b/TC1/http_server/web_log.h @@ -17,17 +17,15 @@ void SetLogRecord(LogRecord* lr, char* log); char* GetLogRecord(); void WebLog(const char *M, ...); -#define TIM_LEN 32 extern LogRecord log_record; extern char* LOG_TMP; -extern time_t now; -extern char time_buf[]; +extern time_t LOG_NOW; #define web_log(N, M, ...) \ 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] "M, time_buf, N, SHORT_FILE, __LINE__, ##__VA_ARGS__); \ + LOG_NOW = time(NULL) + 28800; \ + strftime(LOG_TMP, TIME_LEN, "[%Y-%m-%d %H:%M:%S]", localtime(&LOG_NOW)); \ + LOG_TMP[TIME_LEN - 1] = ' '; \ + snprintf(LOG_TMP + TIME_LEN, LOG_LEN - TIME_LEN, "["N" %s:%d] "M, SHORT_FILE, __LINE__, ##__VA_ARGS__); \ SetLogRecord(&log_record, LOG_TMP); \ #define web_log0(N, M, ...) WebLog("["N" %s:%d] "M, SHORT_FILE, __LINE__, ##__VA_ARGS__) diff --git a/TC1/main.h b/TC1/main.h index 3c4c9df..b0147b2 100644 --- a/TC1/main.h +++ b/TC1/main.h @@ -5,16 +5,16 @@ #include "micokit_ext.h" #include "timed_task/timed_task.h" -#define app_log(M, ...) do { custom_log("APP", M, ##__VA_ARGS__); web_log("APP", M, ##__VA_ARGS__); } while(0) -#define key_log(M, ...) do { custom_log("KEY", M, ##__VA_ARGS__); web_log("KEY", M, ##__VA_ARGS__); } while(0) -#define ota_log(M, ...) do { custom_log("OTA", M, ##__VA_ARGS__); web_log("OTA", M, ##__VA_ARGS__); } while(0) -#define rtc_log(M, ...) do { custom_log("RTC", M, ##__VA_ARGS__); web_log("RTC", M, ##__VA_ARGS__); } while(0) -#define tc1_log(M, ...) do { custom_log("TC1", M, ##__VA_ARGS__); web_log("TC1", M, ##__VA_ARGS__); } while(0) -#define task_log(M, ...) do { custom_log("TASK", M, ##__VA_ARGS__); web_log("TASK", M, ##__VA_ARGS__); } while(0) -#define http_log(M, ...) do { custom_log("HTTP", M, ##__VA_ARGS__); web_log("HTTP", M, ##__VA_ARGS__); } while(0) -#define mqtt_log(M, ...) do { custom_log("MQTT", M, ##__VA_ARGS__); web_log("MQTT", M, ##__VA_ARGS__); } while(0) -#define wifi_log(M, ...) do { custom_log("WIFI", M, ##__VA_ARGS__); web_log("WIFI", M, ##__VA_ARGS__); } while(0) -#define power_log(M, ...) do { custom_log("POWER", M, ##__VA_ARGS__); web_log("POWER", M, ##__VA_ARGS__); } while(0) +#define app_log(M, ...) custom_log("APP", M, ##__VA_ARGS__); web_log("APP", M, ##__VA_ARGS__); +#define key_log(M, ...) custom_log("KEY", M, ##__VA_ARGS__); web_log("KEY", M, ##__VA_ARGS__); +#define ota_log(M, ...) custom_log("OTA", M, ##__VA_ARGS__); web_log("OTA", M, ##__VA_ARGS__); +#define rtc_log(M, ...) custom_log("RTC", M, ##__VA_ARGS__); web_log("RTC", M, ##__VA_ARGS__); +#define tc1_log(M, ...) custom_log("TC1", M, ##__VA_ARGS__); web_log("TC1", M, ##__VA_ARGS__); +#define task_log(M, ...) custom_log("TASK", M, ##__VA_ARGS__); web_log("TASK", M, ##__VA_ARGS__); +#define http_log(M, ...) custom_log("HTTP", M, ##__VA_ARGS__); web_log("HTTP", M, ##__VA_ARGS__); +#define mqtt_log(M, ...) custom_log("MQTT", M, ##__VA_ARGS__); web_log("MQTT", M, ##__VA_ARGS__); +#define wifi_log(M, ...) custom_log("WIFI", M, ##__VA_ARGS__); web_log("WIFI", M, ##__VA_ARGS__); +#define power_log(M, ...) custom_log("POWER", M, ##__VA_ARGS__); web_log("POWER", M, ##__VA_ARGS__); #define VERSION "v2.1.6"