【整理】Linux 下 自己使用的 debug宏 printf
发布时间:2020-12-14 02:05:58 所属栏目:Linux 来源:网络整理
导读:#ifdef __DEBUG_PRINTF__ /* ** Some Debug printf kit for devlopment ** Date : 2019.03.04** Editor : SCHIPS* */ #include stdio.h /* Debug with file name and line. */ #define DEBUG(format,...) printf(""format"n",##__VA_ARGS__ ) #define DEBUG
#ifdef __DEBUG_PRINTF__ /* * * Some Debug printf kit for devlopment * * Date : 2019.03.04 * * Editor : SCHIPS * */ #include <stdio.h> /* Debug with file name and line. */ #define DEBUG(format,...) printf(""format"n",##__VA_ARGS__ ) #define DEBUG_RED(format,...) printf(" 33[30m 33[31m"format" 33[0mn",##__VA_ARGS__) #define DEBUG_GREEN(format,...) printf(" 33[30m 33[32m"format" 33[0mn",##__VA_ARGS__) #define DEBUG_YELLOW(format,...) printf(" 33[30m 33[33m"format" 33[0mn",##__VA_ARGS__) #define DEBUG_PURP(format,...) printf(" 33[30m 33[35m"format" 33[0mn",##__VA_ARGS__) #define DEBUG_BLUE(format,...) printf(" 33[30m 33[36m"format" 33[0mn",##__VA_ARGS__) /* Debug printf infomration with color. */ #define DEBUG_FL(format,...) printf("["__FILE__"](%05d) - %s]n "format"n",__LINE__,##__VA_ARGS__,__FUNCTION__) #define DEBUG_FLR(format,...) printf(" 33[30m 33[31m["__FILE__"](%05d) - %s]n 33[0m "format"n",__FUNCTION__,##__VA_ARGS__) #define DEBUG_FLG(format,...) printf(" 33[30m 33[32m["__FILE__"](%05d) - %s]n 33[0m "format"n",##__VA_ARGS__) #define DEBUG_FLY(format,...) printf(" 33[30m 33[33m["__FILE__"](%05d) - %s]n 33[0m "format"n",##__VA_ARGS__) #define DEBUG_FLP(format,...) printf(" 33[30m 33[35m["__FILE__"](%05d) - %s]n 33[0m "format"n",##__VA_ARGS__) #define DEBUG_FLB(format,...) printf(" 33[30m 33[36m["__FILE__"](%05d) - %s]n 33[0m "format"n",##__VA_ARGS__) #define DEBUG_SFL(format,...) printf("["__FILE__"](%05d) - %s] "format"n",__FUNCTION__) #define DEBUG_SFLR(format,...) printf(" 33[30m 33[31m["__FILE__"](%05d) - %s] 33[0m "format"n",##__VA_ARGS__) #define DEBUG_SFLG(format,...) printf(" 33[30m 33[32m["__FILE__"](%05d) - %s] 33[0m "format"n",##__VA_ARGS__) #define DEBUG_SFLY(format,...) printf(" 33[30m 33[33m["__FILE__"](%05d) - %s] 33[0m "format"n",##__VA_ARGS__) #define DEBUG_SFLP(format,...) printf(" 33[30m 33[35m["__FILE__"](%05d) - %s] 33[0m "format"n",##__VA_ARGS__) #define DEBUG_SFLB(format,...) printf(" 33[30m 33[36m["__FILE__"](%05d) - %s] 33[0m "format"n",##__VA_ARGS__) #define SC_CLEAR() printf(" 33[2J") #if 0 /* Another format to Print (Too ugly to me to use.)*/ #define DEBUGA(fmt,args...) printf("[%s(%05d) - %s]n "#fmt"n",__FILE__,##args) #endif #else #define DEBUG(format,...) #define DEBUG_RED(format,...) #define DEBUG_GREEN(format,...) #define DEBUG_YELLOW(format,...) #define DEBUG_PURP(format,...) #define DEBUG_BLUE(format,...) #define DEBUG_FL(format,...) #define DEBUG_FLR(format,...) #define DEBUG_FLG(format,...) #define DEBUG_FLY(format,...) #define DEBUG_FLP(format,...) #define DEBUG_FLB(format,...) #define DEBUG_SFL(format,...) #define DEBUG_SFLR(format,...) #define DEBUG_SFLG(format,...) #define DEBUG_SFLY(format,...) #define DEBUG_SFLP(format,...) #define DEBUG_SFLB(format,...) #define SC_CLEAR(format,...) #endif #include <stdio.h> #if 1 // To turn on/off Debug printf; #define __DEBUG_PRINTF__ #endif #include "debug.h" void fun1(void) { DEBUG("DEBUG"); DEBUG_RED("RED."); DEBUG_GREEN("GREEN."); DEBUG_YELLOW("YELLOW."); return ; } void fun2(char* buff) { int i = 0; DEBUG_FL("fun2"); DEBUG_FLB("i = %d",i); DEBUG_FLR("buff = %s",buff); DEBUG_FLP("buff = %s",buff); return ; } void fun3(char* buff,int i) { DEBUG_SFL("fun3"); DEBUG_SFLB("i = %d",i); DEBUG_SFLR("buff = %s",buff); DEBUG_SFLP("buff = %s",buff); return ; } int main(void) { SC_CLEAR(); fun1(); printf("---------n"); fun2("fun 2"); printf("---------n"); fun3("fun3",3); return 0; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |