log打印封装

//color
#define FONT_COLOR_NONE     "\033[0m"
#define FONT_COLOR_RED      "\033[0;31m"
#define FONT_COLOR_GREEN    "\033[0;32m"
#define FONT_COLOR_YELLOW   "\033[0;33m"
#define FONT_COLOR_BLUE     "\033[0;34m"
#define FONT_COLOR_PURPLE   "\033[0;35m"
#define FONT_COLOR_GRAY     "\033[0;37m"

//log print level
typedef enum logLevel
{
    LOG_LEVEL_NORMAL = 0x00,
    LOG_LEVEL_DEBUG = 0x01,
    LOG_LEVEL_INFO = 0x02,
    LOG_LEVEL_WARNING = 0x03,
    LOG_LEVEL_ERROR = 0x04  
}LogLevel;

static LogLevel LogLevel = LOG_LEVEL_DEBUG;

#define LOG_NORMAL(format, arg...) \
    do{if (LogLevel <= LOG_LEVEL_NORMAL)  \
    printf(FONT_COLOR_NONE "NORMAL: [THREAD: 0x%x, FILE: %s, FUNCTION: %s, LINE: %d] : "format FONT_COLOR_NONE " \n", \
    (unsigned int)pthread_self(), __FILE__, __FUNCTION__, __LINE__, ##arg); }while(0)

#define LOG_DEBUG(format, arg...) \
    do{if (LogLevel <= LOG_LEVEL_DEBUG)  \
    printf(FONT_COLOR_PURPLE "DEBUG: [THREAD: 0x%x, FILE: %s, FUNCTION: %s, LINE: %d] : "format FONT_COLOR_NONE " \n", \
    (unsigned int)pthread_self(), __FILE__, __FUNCTION__, __LINE__, ##arg); }while(0)
   
#define LOG_INFO(format, arg...) \
    do{if (LogLevel <= LOG_LEVEL_INFO)  \
    printf(FONT_COLOR_GREEN "INFO: [THREAD: 0x%x, FILE: %s, FUNCTION: %s, LINE: %d] : "format FONT_COLOR_NONE " \n", \
    (unsigned int)pthread_self(), __FILE__, __FUNCTION__, __LINE__, ##arg); }while(0)
   
#define LOG_WARNING(format, arg...) \
    do{if (LogLevel <= LOG_LEVEL_WARNING)  \
    printf(FONT_COLOR_YELLOW "WARNING: [THREAD: 0x%x, FILE: %s, FUNCTION: %s, LINE: %d] : "format FONT_COLOR_NONE " \n", \
    (unsigned int)pthread_self(), __FILE__, __FUNCTION__, __LINE__, ##arg); }while(0)
   
#define LOG_ERROR(format, arg...) \
    do{if (LogLevel <= LOG_LEVEL_ERROR)  \
    printf(FONT_COLOR_RED "ERROR: [THREAD: 0x%x, FILE: %s, FUNCTION: %s, LINE: %d] : "format FONT_COLOR_NONE " \n", \
    (unsigned int)pthread_self(), __FILE__, __FUNCTION__, __LINE__, ##arg); }while(0)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值