89 lines
2.5 KiB
C++
89 lines
2.5 KiB
C++
#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 {
|
|
static CTL::WebSocket ws;
|
|
static CCMutex _ws_map_lock;
|
|
public:
|
|
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<typename ...Args>
|
|
static void Log(const CTL::String& fmt, Args... args){
|
|
const CTL::String str = CTL::String::format(fmt.c_str(),args...);
|
|
logger.Info(str);
|
|
}
|
|
template<typename ...Args>
|
|
static void Error(const CTL::String& fmt, Args... args){
|
|
const CTL::String str = CTL::String::format(fmt.c_str(),args...);
|
|
logger.Error(str);
|
|
}
|
|
template<typename ...Args>
|
|
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<CTL::LogParentFile> GetLogs(){
|
|
return logger.GetLogs();
|
|
}
|
|
static CCVector<CTL::LogFile_t> 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
|