#include "log.h" #include "platform.h" #include "common.h" #include #include #include #include "pt-timer.h" #define HLOG_INFO "Hlog " static char logToOutterFlag=0; static char logToUsbFlag=0; #if defined NEED_TIMESTEMP #define HEAD_PART_LEN (35+2) //根据以下的snprintf(pinfo 的长度计算 再加回车换行 char timestp[25]; char *timeStmp(void){ MY_CLOCK myclock; getMyClock(&myclock); snprintf(timestp, sizeof(timestp),"%02d-%02d-%02d %02d:%02d:%02d", myclock.year%100, myclock.month, myclock.day, myclock.hour, myclock.min, myclock.sec); return timestp; } #else #define HEAD_PART_LEN (16+2) //根据以下的snprintf(pinfo 的长度计算 再加回车换行 #endif #define MAX_LOG_INFO_LEN 100 //日志打印的用户段最大有效长度 void wjlprintf(const char *level,const char *format,...){ va_list vags; char pinfo[MAX_LOG_INFO_LEN+HEAD_PART_LEN],info[MAX_LOG_INFO_LEN]; if(logToOutterFlag==0 && logToUsbFlag==0) return; #if defined NEED_TIMESTEMP snprintf(pinfo, sizeof(pinfo), "%s[%s %03d]:",level,timeStmp(),getSysTick()%1000); //"error[20-20-20 20:20:20 000]:" max 29, make it 35 is safe #else snprintf(pinfo, sizeof(pinfo), "%s%s:",HLOG_INFO,level);//"Hlog info/warn/error" max 10, make it 16 is safe #endif va_start(vags, format); vsnprintf(info, sizeof(info),format, vags); va_end(vags); strcat(pinfo, info); strcat(pinfo,"\r\n"); if(0!=logToUsbFlag) ON_SHOW_INFO(pinfo); if(0!=logToOutterFlag) logToOutter(pinfo); #if defined LOG_TO_WIN fflush(stdout); #endif } void setLogRoute(char typeUsb, char typeOutter){ logToOutterFlag=typeOutter; logToUsbFlag=typeUsb; }