优化 web_log

This commit is contained in:
zogodo
2020-01-12 13:18:31 +08:00
parent cdbabf672b
commit e7814de6fd
4 changed files with 10 additions and 9 deletions

View File

@@ -227,7 +227,7 @@ exit:
static int HttpGetLog(httpd_request_t *req)
{
OSStatus err = kNoErr;
char* logs = GetLogRecord(0);
char* logs = GetLogRecord();
send_http(logs, strlen(logs), exit, &err);
exit:

View File

@@ -24,11 +24,9 @@ void SetLogRecord(LogRecord* lr, char* log)
*p_log = log;
}
char* GetLogRecord(int idx)
char* GetLogRecord()
{
if (idx > log_record.idx) return "";
int i = idx > 0 ? idx : (log_record.idx - LOG_NUM + 1);
int i = log_record.idx - LOG_NUM + 1;
i = i < 0 ? 0 : i;
char* tmp = log_record_str;
for (; i <= log_record.idx; i++)
@@ -37,6 +35,7 @@ char* GetLogRecord(int idx)
sprintf(tmp, "%s\n", log_record.logs[i%LOG_NUM]);
tmp += strlen(tmp);
}
sprintf(tmp, "%d", log_record.idx);
return log_record_str;
}

View File

@@ -19,7 +19,7 @@ extern time_t now;
extern char time_buf[];
void SetLogRecord(LogRecord* lr, char* log);
char* GetLogRecord(int idx);
char* GetLogRecord();
#define web_log(format, ...) \
LOG_TMP = (char*)malloc(sizeof(char)*LOG_LEN); \