C语言下,日志的打印等级与特殊的宏定义

日志的打印等级与特殊的宏定义

特殊的宏定义

/*****************************strcat*****************************************/
/* # 字符串化 */
#define		exp(s)	#s   			// exp(145s)	<==>  "145s" 	

/* ##为连接符,用来将宏参数或其他的串连接起来 */
#define		STR_TO_CAT(a, b)	a##b   		// strcat(a, b)	<==> STR_TO_CAT(a, b) 
#define		CON1(a, b)	a##e##b   			// CON1(2.5, 2)	<==> 2.5e2 == 250 
#define		CON2(a, b)	a##b##00   			// CON2(2.5, 2)	<==> 2.5200 	

日志的打印等级

/*****************************strcat*****************************************/
#ifndef _DEBUG_H
#define _DEBUG_H

/* 
 *	when PRINTF_LEVEL == 1 
 *	printf("This is a debug information maro!!!");	<==>	LOG("This is a debug information maro!!!");
 *	printf("a = %d, b = %f\n", a, b);	<==>	LOG("a = %d, b = %f\n", a, b);
 *
 */

#include <stdio.h>

/*****************************SelfPrintf***********************************************/
#define PRINTF_LEVEL 0

#if (PRINTF_LEVEL == 0)
#define	 LOG(...)	printf("COMMON_DEBUG ======= :"__VA_ARGS__)
#define  LOG_ERROR(err_msg)		\
	do { \
		printf("COMMON_DEBUG_ERROR=======: %s:%s:%d", __FILE__, __FUNCTION__, __LINE__);  \
		printf(" (err_msg:%s)\n", err_msg);
	} while(0); \	

#elif (PRINTF_LEVEL == 1)
#define	 LOG(...)	printf(__VA_ARGS__)
#define  LOG_ERROR(err_msg)		\
	do { \
		printf("ERROR=======: %s:%s:%d", __FILE__, __FUNCTION__, __LINE__);  \
		printf(" (err_msg:%s)\n", err_msg);		\
	} while(0); 

#else
#define LOG(...) 
#define LOG_ERROR(err_msg) 
#endif


#endif

调试必备宏定义

#define 	DBG_ERR_IFO(fmt, args...)  	printf("The position of error information[%s:%s(%d)]:" fmt "\n", __FILE__,__FUNCTION__, __LINE__, ##args)

// 第一个参数传给fmt, 
// 第二个参数开始传给args..., 
// #fmt的=的意思是把fmt传进来的内容以字符串形式输出
// ##args的意思=是把args...中的多个参数串连起来。

DBG_ERR_IFO(“the value a = %d, b = %d\n”, a, b);printf("The position of error information[%s:%s(%d)]:" “the value a = %d, b = %d\n” "\n", __FILE__,__FUNCTION__, __LINE__, a, b);


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值