#pragma once #include "String.Format.tlh" #include "SystemLog.hpp" #ifndef XDWLog_EXPORTS #define AppTLSLog_API _declspec(dllimport) #else #define AppTLSLog_API _declspec(dllexport) #endif #pragma warning (disable : 4996) //warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. //To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. namespace ECOM { namespace Log { AppTLSLog_API void Flush (CSystemLog * pLog, const char * str); AppTLSLog_API void NewLine (CSystemLog * pLog); class AppTLSLog_API TLSLog { static const int MAXLEN = 8192 + 1; // Log 一行的最大长度 protected: TLSLog () = delete; protected: static char * TlsGetBuffer (); public: // 改成 public, 作为测试用, 本来是可以 protected template static inline char * Format (const char * src, Args... args) { auto buf_org = TlsGetBuffer (); auto len = ECOM::Utility::StringFormat (buf_org, MAXLEN).Format (src, args...); return buf_org; } public: static void Flush (CSystemLog * pLog, CSystemLog::Severity s); #if 0 protected: template static void Log (CSystemLog * pLog, const char * format, Args... args) { Format ((char *) format, args...); Flush (pLog, CSystemLog::STY_DEBUG); } template static void Info (CSystemLog * pLog, const char * format, Args... args) { Format ((char *) format, args...); Flush (pLog, CSystemLog::STY_INFO); } template static void Warning (CSystemLog * pLog, const char * format, Args... args) { Format ((char *) format, args...); Flush (pLog, CSystemLog::STY_WARNING); } //< 不写到错误日志中 template static void Error (CSystemLog * pLog, const char * format, Args... args) { Format ((char *) format, args...); Flush (pLog, CSystemLog::STY_ERROR); } template static void Fatal (CSystemLog * pLog, const char * format, Args... args) { Format ((char *) format, args...); Flush (pLog, CSystemLog::STY_CRITICAL); } //> //< 写到错误日志中 template static void Error (CSystemLog * pLog, CSystemLog * pErr, const char * format, Args... args) { Format ((char *) format, args...); Flush (pLog, CSystemLog::STY_ERROR); Flush (pErr, CSystemLog::STY_ERROR); } template static void Fatal (CSystemLog * pLog, CSystemLog * pErr, const char * format, Args... args) { Format ((char *) format, args...); Flush (pLog, CSystemLog::STY_CRITICAL); Flush (pErr, CSystemLog::STY_CRITICAL); } //> #endif }; } }