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)



你可能感兴趣的:(log打印封装)