以下在linux下测试有效
#include <stdio.h>
#include <time.h>
#include <chrono>
using namespace std;
static const char* tag = "main";
static const char tag_debug = 1;
static const char tag_user_milli_sec = 0;
#define LOG (printf("%s (%d) - <%s>\n",__FILE__,__LINE__,__FUNCTION__),printf)
#define my_log(format, ...)\
do{\
time_t time_val=time(NULL);\
char* ctr = ctime(&time_val);\
ctr[24] = '\0';\
printf("[%s] %s (%d) - <%s> : "#format " \n", ctr, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \
}while(0)
#define print_log(format, ...) \
do{ \
if(tag_debug == 1){\
if(tag_user_milli_sec == 1){\
static struct timespec ts;\
clock_gettime(CLOCK_REALTIME, &ts);\
printf("%ld:%d : %s : %d D:"#format " \n", ts.tv_sec,ts.tv_nsec/(1000*1000), tag, __LINE__, ##__VA_ARGS__); \
}\
else {\
time_t time_val=time(NULL);\
char* ctr = ctime(&time_val);\
ctr[24] = '\0';\
printf("%s : %s : %d D:"#format " \n", ctr, tag, __LINE__, ##__VA_ARGS__); \
}\
} \
}while(0)
void test(){
my_log("what's this %d",120);
LOG;
}
int main(){
my_log("what's this");
test();
LOG;
return 0;
}