#pragma once #include #include #include #include #include #include #include #include #define LOG_DEBUG Logger::GetInstance()->Log class Logger { public: Logger(); ~Logger(); bool Init(const std::string& logDir, const std::string& logFileName); bool Start(); bool Stop(); std::string Log(const char* format, ...); //static Logger* GetInstance() { return &pInstance; } static std::shared_ptr GetInstance() { return pInstance; } private: Logger(const Logger&) = default; Logger& operator=(const Logger&) = default; void __pushLogItem(const std::string& data, const int& level, const std::string& content); void __dealLogItem(); std::shared_ptr __openFile(); private: typedef struct tagLogItem { std::string Date; std::string Content; int Level; tagLogItem(const std::string& date) { Date = date; Content = ""; Level = 0; } void SetItem(const int& Level, const std::string& Content) { this->Level = Level; this->Content = Content; } std::string string() { std::string str; str.append(this->Date).append(" ["); str.append(this->Level == 0 ? "调试" : "信息").append("] "); str.append(this->Content).append("\n"); return str; } friend std::ostream& operator<< (std::ostream& os, const tagLogItem&a) { return os << a.Date << " [" << (a.Level == 0 ? "调试" : "信息") << "] " << a.Content << std::endl; } }LogItem; std::list> m_LogList; std::mutex m_LogMut; std::condition_variable m_LogCond; bool m_isStop; std::shared_ptr m_LogThread; int m_LogSize; // 文件大小,单位M std::string m_LogDir; // 日志文件夹 std::string m_LogFileName;// 日志文件名 //static Logger pInstance; static std::shared_ptr pInstance; };