封装一
#define my_debug_firmware printf
#define my_app_debug(x,y...) my_debug_firmware("app debug =>fun(%s)line:%d:->"x,__FUNCTION__,__LINE__,##y)
#define my_net_debug(x,y...) my_debug_firmware("net debug =>fun(%s)line:%d:->"x,__FUNCTION__,__LINE__,##y)
#define print_array_debug(data, datalength) do\
{\
int i;\
my_debug_firmware("datalen=%d.\r\n", datalength);\
for (i = 0; i < datalength; i++) {\
my_debug_firmware("%02X ",(unsigned char)data[i]);\
}\
my_debug_firmware("\r\n");\
}while(0)
#define print_string_debug(data, datalength) do\
{\
int i;\
my_debug_firmware("datalen=%d.\r\n", datalength);\
for (i = 0; i < datalength; i++) {\
my_debug_firmware("%c",(unsigned char)data[i]);\
}\
my_debug_firmware("\r\n");\
}while(0)
封装二
#include <stdio.h>
#include <stdarg.h>
void MyPrintf(const char *cmd, ...)
{
struct timeval tv;
gettimeofday(&tv,NULL);
printf("MS: %ld ", tv.tv_sec*1000 + tv.tv_usec/1000);
printf("file:%s line:%s fun: %s -> ", __FILE__,__LINE__, __FUNCTION__);
va_list args;
va_start(args,cmd);
vprintf(cmd,args);
va_end(args);
printf("\n");
}
#include<iostream>
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>
int main(){
struct timeval tv;
gettimeofday(&tv,NULL);
printf("second:%ld\n",tv.tv_sec);
printf("millisecond:%ld\n",tv.tv_sec*1000 + tv.tv_usec/1000);
printf("microsecond:%ld\n",tv.tv_sec*1000000 + tv.tv_usec);
sleep(1);
MyPrintf("test");
return 0;
}