#ifndef __LOG_H__ #define __LOG_H__ #include "type.h" #ifdef WIN32 #define filename(x) strrchr(x,'\\')?strrchr(x,'\\')+1:x #else #if __GNUC__ >= 4 #define filename(x) strrchr(x,'/')?strrchr(x,'/')+1:x #endif #endif EXPORT_API INT32 initLog(const char* loggerName, const char* fileName, int level, bool openConsole = true); EXPORT_API void logTrace(const char* pcLogStr); EXPORT_API void logDebug(const char* pcLogStr); EXPORT_API void logInfo(const char* pcLogStr); EXPORT_API void logWarn(const char* pcLogStr); EXPORT_API void logError(const char* pcLogStr); EXPORT_API void logCritical(const char* pcLogStr); EXPORT_API UINT64 gettid(); #define CREATE_LOG_HEAD \ char acLogStr[1024*4] = {0};\ INT32 iHeadLength = snprintf(acLogStr, 1024*4, "[tid:%llu] : ", gettid());\ //INT32 iHeadLength = snprintf(acLogStr, 1024*4, "[tid:%llu] [%s:%d] %s: ", gettid(), filename(__FILE__), __LINE__, __FUNCTION__);\ #define LOG_TRACE(...) \ {\ CREATE_LOG_HEAD\ snprintf(acLogStr+iHeadLength, sizeof(acLogStr)-iHeadLength, __VA_ARGS__);\ logTrace(acLogStr);\ } #define LOG_DEBUG(...) \ {\ CREATE_LOG_HEAD\ snprintf(acLogStr+iHeadLength, sizeof(acLogStr)-iHeadLength, __VA_ARGS__);\ logDebug(acLogStr);\ } #define LOG_INFO(...) \ {\ CREATE_LOG_HEAD\ snprintf(acLogStr+iHeadLength, sizeof(acLogStr)-iHeadLength, __VA_ARGS__);\ logInfo(acLogStr);\ } #define LOG_WARN(...) \ {\ CREATE_LOG_HEAD\ snprintf(acLogStr+iHeadLength, sizeof(acLogStr)-iHeadLength, __VA_ARGS__);\ logWarn(acLogStr);\ } #define LOG_ERROR(...) \ {\ CREATE_LOG_HEAD\ snprintf(acLogStr+iHeadLength, sizeof(acLogStr)-iHeadLength, __VA_ARGS__);\ logError(acLogStr);\ } #endif // __LOG_H__