new web_log()

This commit is contained in:
zogodo
2020-12-02 11:42:20 +08:00
parent c18dadf123
commit a55b4445ec
2 changed files with 19 additions and 1 deletions

View File

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

View File

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