log4c、zlog、EasyLogger
http://log4c.sourceforge.net/index.html
http://hardysimpson.github.io/zlog/
https://github.com/HardySimpson/zlog
https://github.com/armink/EasyLogger
https://blog.csdn.net/shaohuazuo/article/details/39179643
#include <stdarg.h> #include "main.h" typedef enum { LogLevel_begin = -1, LogLevel_Trace, LogLevel_Debug, LogLevel_Info, LogLevel_Error, LogLevel_Fatal, LogLevel_end } LogLevel_em; #define PER_LOG_LINE_SIZE 512 static LogLevel_em w_emCurLogLevel = LogLevel_Debug ; //log level switch static void Send_logMsg(char* w_Msg, uint32_t u32MsgLen); static void Logger_putMsg(LogLevel_em emLvl, const char* pcszBodyFmt, va_list vaBodyArgs); void Logger_trace( const char * w_Fmt, ...) { va_list vaList; va_start(vaList, w_Fmt); Logger_putMsg(LogLevel_Trace, w_Fmt, vaList); va_end(vaList); } void Logger_debug(const char * w_Fmt, ...) { va_list vaList; va_start(vaList, w_Fmt); Logger_putMsg(LogLevel_Debug, w_Fmt, vaList); va_end(vaList); } void Logger_info( const char * w_Fmt, ...) { va_list vaList; va_start(vaList, w_Fmt); Logger_putMsg(LogLevel_Info, w_Fmt, vaList); va_end(vaList); } void Logger_error( const char * w_Fmt, ...) { va_list vaList; va_start(vaList, w_Fmt); Logger_putMsg(LogLevel_Error, w_Fmt, vaList); va_end(vaList); } void Logger_fatal( const char * w_Fmt, ...) { va_list vaList; va_start(vaList, w_Fmt); Logger_putMsg(LogLevel_Fatal, w_Fmt, vaList); va_end(vaList); } static void Logger_putMsg(LogLevel_em emLvl, const char* pcszBodyFmt, va_list vaBodyArgs){ if (w_emCurLogLevel <= emLvl) { static char s_strMsg[PER_LOG_LINE_SIZE]; uint32_t u32Len; u32Len = vsnprintf(s_strMsg, PER_LOG_LINE_SIZE, pcszBodyFmt, vaBodyArgs)-1; #if 0 s_strMsg[u32Len++]=' '; s_strMsg[u32Len]='