C/C++普段使うカスタムdebug関数の開発


一、無色版
 、   printf
#include <stdio.h>
#ifdef MYDEBUG
#define DEBUG(arg...) {\
printf("[debug]:%s:%s:%d ---->",__FILE__,__FUNCTION__,__LINE__);\
printf(arg);\
fflush(stdout);\
}
#else
#define DEBUG(arg...) {}
#endif
    :
DEBUG("my debug......
"); DEBUG("the a is %d
",a); 、 printf #ifdef DEBUG #define D_STR(_STR_) printf("f:%s(l:%d)%s
",__FILE__,__LINE__,_STR_); #define D_LINE printf("f:%s(l:%d)-fn:%s
",__FILE__,__LINE__,__FUNCTION__); #define D_CHAR(_CHAR_) printf("f:%s(l:%d)%d
",__FILE__,__LINE__,_CHAR_); #define D_HEX(_HEX_) printf("f:%s(l:%d)[%x]
",__FILE__,__LINE__,_HEX_); #else #define D_STR(_STR_) ; #define D_LINE ; #define D_CHAR(_CHAR_) ; #define D_HEX(_HEX_) ; #endif 、vfprintf static void fprint_message_to_stdout(const char *format, va_list arg_ptr) { (void) vfprintf(stdout, format, arg_ptr); }

二、カラー版
#define printf_error(s) \
	printf("\e[1;31m%s\e[0m
", s); #define printf_run(s) \ printf("\e[1;32m%s\e[0m
", s); #define printf_warn(s) \ printf("\e[1;33m%s\e[0m
", s); #define printf_log(s,t) \ switch (t) \ { \ case LT_ERROR: \ printf_error(s); \ break; \ case LT_RUNINFO: \ printf_run(s); \ break; \ case LT_ALARM: \ printf_warn(s); \ default: \ printf(s); \ break; \ } \

本文はブロガーのオリジナル文章で、ブロガーの許可を得ずに転載してはならない.