#ifndef OH_BS_BS_LOG_H #define OH_BS_BS_LOG_H #include "CCString.h" #include "CCLogger.h" #include "CCWebSocket.h" #include "TL/Map.h" #include "CCFile.h" #include "CCSystem.h" #include "Config.h" class BS_Log { inline static CTL::WebSocket ws; inline static CCMutex _ws_map_lock; public: inline static CTL::Logger logger; static void Stop(){ logger.Stop(); } static void Init(){ const auto Path = CCFile::NormalizePath(Config::GetFileDir() + "/Logs/"); CCFile file(Path); if(!file.isExists()){ CCFile::Create(Path,true); } logger.SetLogFolder(Path); logger.SetLevel(CTL::Logger_Level::Debug); logger.SetLogCount(3); logger.SetLogSave(7); logger.SetLogSize(30 * 1024); logger.Start(); } template static void Log(const CTL::String& fmt, Args... args){ const CTL::String str = CTL::String::format(fmt.c_str(),args...); logger.Info(str); } template static void Error(const CTL::String& fmt, Args... args){ const CTL::String str = CTL::String::format(fmt.c_str(),args...); logger.Error(str); } template static void Warning(const CTL::String& fmt, Args... args){ const CTL::String str = CTL::String::format(fmt.c_str(),args...); logger.Warning(str); } static CCVector GetLogs(){ return logger.GetLogs(); } static CCVector GetLogFiles(const CTL::String& Date) { return logger.GetLogFiles(Date); } static CTL::String GetDate() { return logger.GetCurrentDate(); } static CTL::String GetLog(const CTL::String& Date, const CTL::String& FileName) { return logger.GetLog(Date,FileName); } static CTL::String GetLogFile(const CTL::String& Date, const CTL::String& FileName) { return logger.GetLogFile(Date,FileName); } static bool Delete(const CTL::String& Date, const CTL::String& FileName) { return logger.DeleteLog(Date,FileName); } static void Flush() { logger.Flush(); } private: static void OnOpen(CTL::WebSocketInfo& info){ CTL::Thread([&](){ CTL::Thread::SleepMS(5000); Log(CTL::String("LOG OPEN OK")); }).Start(); } static void OnMessage(CTL::WebSocketInfo& info){ } static void OnClose(CTL::WebSocketInfo& info){ } static void OnPing(CTL::WebSocketInfo& info){ info.SendPong("ABC"); } }; #endif