仅供参考,不推荐
#ifdef _DEBUG
#define LOGDEBUG(format, ...)
{
FILE *fp = fopen("nccli.log", "ab+");if(fp!=NULL){
time_t t = time(0);
struct tm ttt = *localtime(&t);
fprintf(fp, "[DEBUG] [%5d %4d-%02d-%02d %02d:%02d:%02d] [%s:%d] " format "",
GetCurrentProcessId(), ttt.tm_year + 1900, ttt.tm_mon + 1, ttt.tm_mday, ttt.tm_hour,
ttt.tm_min, ttt.tm_sec, __FUNCTION__ , __LINE__, ##__VA_ARGS__);
fclose(fp);}
}
#define LOGERROR(format, ...)
{
FILE *fp = fopen("nccli.log", "ab+");if(fp!=NULL){
time_t t = time(0);
struct tm ttt = *localtime(&t);
fprintf(fp, "[ERROR] [%5d %4d-%02d-%02d %02d:%02d:%02d] [%s:%d] " format "",
GetCurrentProcessId(), ttt.tm_year + 1900, ttt.tm_mon + 1, ttt.tm_mday, ttt.tm_hour,
ttt.tm_min, ttt.tm_sec, __FUNCTION__ , __LINE__, ##__VA_ARGS__);
fclose(fp);}
}
#else
#define LOGDEBUG(format, ...)
{
time_t t = time(0);
struct tm ttt = *localtime(&t);
fprintf(stdout, "[DEBUG] [%5d %4d-%02d-%02d %02d:%02d:%02d] [%s:%d] " format "",
GetCurrentProcessId(), ttt.tm_year + 1900, ttt.tm_mon + 1, ttt.tm_mday, ttt.tm_hour,
ttt.tm_min, ttt.tm_sec, __FUNCTION__ , __LINE__, ##__VA_ARGS__);
}
#define LOGERROR(format, ...)
{
time_t t = time(0);
struct tm ttt = *localtime(&t);
fprintf(stderr, "[ERROR] [%5d %4d-%02d-%02d %02d:%02d:%02d] [%s:%d] " format "",
GetCurrentProcessId(), ttt.tm_year + 1900, ttt.tm_mon + 1, ttt.tm_mday, ttt.tm_hour,
ttt.tm_min, ttt.tm_sec, __FUNCTION__ , __LINE__, ##__VA_ARGS__);
}
#endif