在程序调试时log日志至关重要,笔者实现了一套linux log机制,主要功能如下
#define ANSI_BLACK "30m" /* Black */ #define ANSI_RED "31m" /* Red */ #define ANSI_GREEN "32m" /* Green */ #define ANSI_YELLOW "33m" /* Yellow */ #define ANSI_BLUE "34m" /* Blue */ #define ANSI_MAGENTA "35m" /* Magenta */ #define ANSI_CYAN "36m" /* Cyan */ #define ANSI_WHITE "37m" /* White */ #define ANSI_START "\033[" #define ANSI_RESET "\033[0m" #define COLOR_INFO ANSI_GREEN #define COLOR_DEBUG ANSI_BLUE #define COLOR_WARN ANSI_YELLOW #define COLOR_ERROR ANSI_RED
//demo: void linux_log_demo(void) { LOG_ERROR("This is %s : 0x%.4x ", "LOG_ERRTR",0x00FF); LOG_WARN("This is %s ","LOG_WARN!"); LOG_INFO("This is %s ","LOG_INFO"); LOG_DEBUG("This is %s ","LOG_DEBUG!"); while(1) { LOG_INFO("This is %s ","LOG_INFO"); LOG_DEBUG("This is %s ","LOG_DEBUG!"); //usleep(100000); sleep(1); } }
/* level switch */ #define LOG_ERROR_ENABLE 1 #if LOG_ERROR_ENABLE #define LOG_WARN_ENABLE 1 #if LOG_WARN_ENABLE #define LOG_INFO_ENABLE 0 #if LOG_INFO_ENABLE #define LOG_DEBUG_ENABLE 1 #endif #endif #endif
#define LOG_MORE_MSG_ENABLE 1 /* more mesage .such as file,fun,line,time */ #define LOG_SHOW_DATE_ENABLE 0 /* date in more mesage */
https://github.com/AntigravityC/linux_log
喜欢的点个星星吧(抱拳:)