#ifndef _LOG_H_ #define _LOG_H_
#include <stdio.h> #include <stdarg.h> #include <string.h> #include <time.h>
#ifdef DEBUG #define GENPRINTF(format,...) debug_print(__FILE__, __LINE__, __FUNCTION__, format, ##__VA_ARGS__) #else #define GENPRINTF(format,...) #endif
#define GENPRINTF_1(...) printf(__VA_ARGS__); #define GENPRINTF_2(format,...) printf(format, __VA_ARGS__); #define GENPRINTF_3(format,...) printf(format, ##__VA_ARGS__); #define GENPRINTF_4(level,format,...) printf("%d : %s : %s : %d @ "format, level, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__);
void debug_print(const char* file, const int line, const char* fun, const char* format,...) { char buf[1024]; time_t seconds; struct tm* ptime; seconds = time((time_t*)(NULL)); ptime = localtime(&seconds);
va_list ap; va_start(ap, format); //FILE *fp; //fp = fopen("log","a+"); //if(NULL == fp) { // perror("fopen"); //} fprintf(stdout,"%04d-%02d-%02d %02d:%02d:%02d--%s[%04d]: %s :<<", ptime->tm_year + 1900, ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_hour, ptime->tm_min, ptime->tm_sec, file, line, fun); vsprintf(buf, format, ap); fprintf(stdout, "%s>>\n", buf); va_end(ap); //fclose(fp); }
#endif
|