123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- #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 <typename... Args>
- 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 <typename... Args>
- static void Log (CSystemLog * pLog, const char * format, Args... args)
- {
- Format ((char *) format, args...);
- Flush (pLog, CSystemLog::STY_DEBUG);
- }
- template <typename... Args>
- static void Info (CSystemLog * pLog, const char * format, Args... args)
- {
- Format ((char *) format, args...);
- Flush (pLog, CSystemLog::STY_INFO);
- }
- template <typename... Args>
- static void Warning (CSystemLog * pLog, const char * format, Args... args)
- {
- Format ((char *) format, args...);
- Flush (pLog, CSystemLog::STY_WARNING);
- }
- //< 不写到错误日志中
- template <typename... Args>
- static void Error (CSystemLog * pLog, const char * format, Args... args)
- {
- Format ((char *) format, args...);
- Flush (pLog, CSystemLog::STY_ERROR);
- }
- template <typename... Args>
- static void Fatal (CSystemLog * pLog, const char * format, Args... args)
- {
- Format ((char *) format, args...);
- Flush (pLog, CSystemLog::STY_CRITICAL);
- }
- //>
- //< 写到错误日志中
- template <typename... Args>
- 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 <typename... Args>
- 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
- };
- }
- }
|