简化日志

This commit is contained in:
zogodo
2020-01-10 20:24:26 +08:00
parent 4cba7ebb90
commit 801fc8eccb
4 changed files with 16 additions and 3 deletions

View File

@@ -43,6 +43,7 @@
#include "user_power.h"
#include "main.h"
#include "web_data.c"
#include "web_log.h"
#include "timed_task/timed_task.h"
#include "ota_server/user_ota.h"

View File

@@ -7,6 +7,8 @@
LogRecord log_record = { 1,{ 0 } };
char log_record_str[LOG_NUM*LOG_LEN] = { 0 };
char* LOG_TMP;
time_t now;
char time_buf[TIM_LEN];
void SetLogRecord(LogRecord* lr, char* log)
{

View File

@@ -1,8 +1,14 @@
#include <time.h>
#include "mico.h"
#include "micokit_ext.h"
#include "sys/time.h"
#ifndef WEB_LOG_H
#define WEB_LOG_H
#define LOG_NUM 100
#define LOG_LEN 128
#define TIM_LEN 32
typedef struct
{
@@ -12,13 +18,17 @@ typedef struct
extern LogRecord log_record;
extern char* LOG_TMP;
extern time_t now;
extern char time_buf[];
void SetLogRecord(LogRecord* lr, char* log);
char* GetLogRecord(int idx);
#define web_log(format, ...) \
LOG_TMP = (char*)malloc(sizeof(char)*LOG_LEN); \
snprintf(LOG_TMP, LOG_LEN, format, ##__VA_ARGS__); \
now = 1234567; \
strftime(time_buf, TIM_LEN, "[%Y-%m-%d %H:%M:%S]", localtime(&now)); \
snprintf(LOG_TMP, LOG_LEN, "%s"format, time_buf, ##__VA_ARGS__); \
SetLogRecord(&log_record, LOG_TMP); \
#endif // !WEB_LOG_H

View File

@@ -163,8 +163,8 @@ void rtc_thread(mico_thread_arg_t arg)
// MicoRtcSetTime(&rtc_time); //MicoRtc不自动走时!
if (rtc_time.sec == 0)
os_log("time1:20%02d/%02d/%02d %d %02d:%02d:%02d",rtc_time.year,rtc_time.month,rtc_time.date,rtc_time.weekday,rtc_time.hr,rtc_time.min,rtc_time.sec);
//if (rtc_time.sec == 0)
//os_log("time1:20%02d/%02d/%02d %d %02d:%02d:%02d",rtc_time.year,rtc_time.month,rtc_time.date,rtc_time.weekday,rtc_time.hr,rtc_time.min,rtc_time.sec);
char update_user_config_flag = 0;
for (i = 0; i < SOCKET_NUM; i++)