定义颜色打印输出头文件"print_level.h"

#ifndef _PRINT_LEVEL_H_
#define _PRINT_LEVEL_H_

#ifdef __cplusplus
extern "C" {
#endif

#include<stdio.h>

enum _LEVEL_N{	
	ERROR=0,	
	INFO,
	WARN,
	DEBUG,	
	ALWAYS,	
};

#define COLOR_NONE 				"\033[0m"
#define COLOR_RED               "\033[0;31m"
#define COLOR_GREEN             "\033[0;32m"
#define COLOR_YELLOW            "\033[1;33m"
#define COLOR_LIGHT_CYAN        "\033[1;36m"
#define COLOR_WHITE             "\033[1;37m"

#ifndef PRINT_LEVEL
#define PRINT_LEVEL WARN
#endif


#define print_level(level,fmt,arg...) do {\
	if(level <= PRINT_LEVEL)\
	{\
		const char* pszColor = NULL;\
		switch(level)\
		{\
			case ERROR:\
				pszColor = COLOR_RED;\
				break;\
			case INFO:\
				pszColor = COLOR_LIGHT_CYAN;\
				break;\
			case WARN:\
				pszColor = COLOR_YELLOW;\
				break;\
			case DEBUG:\
				pszColor = COLOR_GREEN;\
				break;\
			default:\
				pszColor = COLOR_WHITE;\
				break;\
		}\
		printf("%s %s>%s:#%d, "COLOR_NONE" "fmt, pszColor, __FILE__, __FUNCTION__, __LINE__, ##arg);\
	}\
	} while(0)

		
#ifdef __cplusplus
}
#endif

#endif


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值