Summarize the macro definitions of several log print printf functions http://blog.chinaunix.net/uid-20564848-id-73402.html
#include <stdio.h>#defineLu_debug_prefix "##########"#defineLu_debug_cmd 0x01#defineLu_debug_data 0x02#defineLu_debug_error 0x04#defineLu_printf_cmd (msg ...) do{if (G_lu_debugs_level & Lu_debug_cmd) PRINTF (Lu_debug_prefix msg); while (0)#defineLu_printf_data (msg ...) do{if (G_lu_debugs_level & Lu_debug_data) PRINTF (Lu_debug_prefix msg); while (0)#defineLu_printf_error (msg ...) do{if (G_lu_debugs_level & Lu_debug_error) PRINTF (Lu_debug_prefix msg); while (0)#defineLu_printf (level, MSG ...) lu_printf_# #level (msg)#defineLU_PRINTF2 (...) printf (__va_args__)#defineLU_PRINTF3 (...) lu_printf (__va_args__)Static intLu_printf4_format (intPrioConst Char*fmt, ...);#defineLu_printf4 (Prio, FMT ...) lu_printf4_format (Prio, FMT)intG_lu_debugs_level;//Global switch to control print level//lu_printf A kernel-like hierarchical print macro that determines whether the output of this sentence is printed based on the G_lu_debugs_level and the first label name of the input. //lu_printf3 equivalent to lu_printf//LU_PRINTF2 equivalent to printf//Lu_printf4 is equivalent to Lu_printf4_format, which is to print the first integer parameter of input in <val> format .intMainintargcChar*argv[]) {G_lu_debugs_level|= Lu_debug_cmd | Lu_debug_data |Lu_debug_error; printf ("g_lu_debugs_level =%p\n", G_lu_debugs_level); lu_printf (cmd,"This is cmd\n"); lu_printf (data,"This is data\n"); lu_printf (Error,"This is error\n"); G_lu_debugs_level&= ~ (Lu_debug_cmd |lu_debug_data); printf ("g_lu_debugs_level =%p\n", G_lu_debugs_level); lu_printf (cmd,"This is cmd\n"); lu_printf (data,"This is data\n"); lu_printf (Error,"This is error\n"); LU_PRINTF2 ("aa%d,%s,%dbbbbb\n", -,"eeeeeee", -); G_lu_debugs_level|= Lu_debug_cmd | Lu_debug_data |Lu_debug_error; printf ("g_lu_debugs_level =%p\n", G_lu_debugs_level); LU_PRINTF3 (cmd,"This is cmd \ n"); LU_PRINTF3 (data,"This is data\n"); LU_PRINTF3 (Error,"This is error\n"); LU_PRINTF4 (0,"Luther%s,%d,%d\n","gliethttp",1,2); return 0;} #include<stdarg.h>Static intLu_printf4_format (intPrioConst Char*FMT, ...) {#defineLog_buf_size (4096)va_list ap; CharBuf[log_buf_size]; Va_start (AP, FMT); vsnprintf (buf, log_buf_size, FMT, AP); Va_end (AP); printf ("<%d>:%s", Prio, buf); printf ("------------------------\ n"); printf (BUF);}#defineEnter () logd ("Enter into%s", __function__)#defineLOGD (...) (void) LOG (Log_debug, Log_tag, __va_args__))#defineLOG (priority, tag, ...) \Log_pri (android_# #priority, Tag, __va_args__)#defineLog_pri (priority, tag, ...) \Android_printlog (priority, tag, __va_args__)#defineAndroid_printlog (Prio, tag, fmt ...) \__android_log_print (prio, Tag, FMT)
C: Hierarchical debug Macros (print macros) similar to Linux kernels