优化web_log写法

This commit is contained in:
zogodo
2022-04-10 15:28:55 +08:00
parent 66bd1bca0d
commit e1e00b60ce
3 changed files with 16 additions and 20 deletions

View File

@@ -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 };

View File

@@ -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__)

View File

@@ -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"