#pragma once #include #define LEVEL_DEBUG 0 #define LEVEL_INFO 1 #define LEVEL_WARN 2 #define LEVEL_ERROR 3 #define LOGD(msg, ...) CLog::GetLog()->LogFormat(LEVEL_DEBUG, "", msg, __VA_ARGS__) #define LOGI(msg, ...) CLog::GetLog()->LogFormat(LEVEL_INFO, "", msg, __VA_ARGS__) #define LOGW(msg, ...) CLog::GetLog()->LogFormat(LEVEL_WARN, "", msg, __VA_ARGS__) #define LOGE(msg, ...) CLog::GetLog()->LogFormat(LEVEL_ERROR, "", msg, __VA_ARGS__) #define OT_FILE 0x01 #define OT_ODSTRING 0x02 #define OT_TRACE 0x04 #define LOGBATHCH() CLog::GetLog()->Batch() #define LOGNEW() CLog::GetLog()->BatchAndNew() typedef std::function ONLOG; class CLog { public: CLog(); ~CLog(); public: void SetOnLogCallback(ONLOG funOnLog); static CLog *GetLog(void); void SetOutputTarget(int flag); void SetEquipmentId(const char* pszEquipmentId); static CString& GetCurTime(CString& strTime); CString& MakeFilepath(CString& strFilepath); CString& MakeFilepathD(CString& strFilepath, int& day); void LogFormat(int nLevel, const char* pszTag, char* szMessage, ...); void Log(int nLevel, const char* pszTag, const char* szMessage); void SetAutoAppendTimeString(BOOL bAutoAppendTime); void SetLogsDir(CString strDir); void Batch(); BOOL BatchAndNew(int& nDay); private: inline void Lock() { EnterCriticalSection(&m_criticalSection); } inline void Unlock() { LeaveCriticalSection(&m_criticalSection); } private: ONLOG m_funOnLog; int m_nOutputTarget; int m_nLevel; BOOL m_bAutoAppendTime; CString m_strLogsDir; CString m_strEquipmentId; CStdioFile m_file; int m_nDay; // °´ÈÕ±£´æÒ»Ìõ¼Ç¼£¬±È½Ï´ËÊý×Ö£¬ÒÔ¾ö¶¨ÊÇ·ñ½áÅú²¢´´½¨ÐÂÎļþ CRITICAL_SECTION m_criticalSection; };