#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
定义颜色打印输出头文件"print_level.h"
最新推荐文章于 2024-03-16 12:18:53 发布