#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++]='\n'; s_strMsg[u32Len]='\0'; #endif Send_logMsg(s_strMsg,u32Len); } } static void Send_logMsg(char* w_Msg, uint32_t u32MsgLen){ #if 1 printf_log(w_Msg,u32MsgLen); //需要自己现实 #endif }
时间: 2024-11-02 22:00:57