#include <stdlib.h> #include <stdio.h> #define APREFIX_NONE "\033[0m" #define APREFIX_RED "\033[0;31m" #define APREFIX_GREEN "\033[0;32m" #define APREFIX_YELLOW "\033[1;33m" #define __P_DEBUG__ #ifdef __P_DEBUG__ #define P_DEBUG(format, args...) printf(APREFIX_GREEN"DEBUG : FILE -> %s, LINE -> %d, FUNCTION -> %s : " format APREFIX_NONE"\n", __FILE__, __LINE__,__FUNCTION__, ## args) #define P_WARRING(format, args...) printf(APREFIX_YELLOW"WARRING : FILE -> %s, LINE -> %d, FUNCTION -> %s : " format APREFIX_NONE"\n", __FILE__, __LINE__,__FUNCTION__, ## args) #define P_ERR(format, args...) printf(APREFIX_RED"ERR : FILE -> %s, LINE -> %d, FUNCTION -> %s : " format APREFIX_NONE"\n", __FILE__, __LINE__,__FUNCTION__, ## args) #else #define P_DEBUG(format,...) #define P_WARRING(format,...) #define P_ERR(format,...) #endif int main(int argc, char **argv) { char str[]="Hello World"; P_DEBUG("A ha, check me: %s",str); P_WARRING("SDF %s",str); P_ERR("sdfsd %s",str); return 0; }
运行结果: