首页 > 代码库 > C语言 log等级_实现
C语言 log等级_实现
#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 }
C语言 log等级_实现
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。