Service_NSSM/CC_SDK/Include/Module/File/CCLogger.h

121 lines
3.7 KiB
C
Raw Normal View History

2025-09-27 14:24:18 +08:00
#ifndef CC_LOGGER_H
#define CC_LOGGER_H
#include "CC.h"
#include "CCTimer.h"
namespace CTL {
/**
*
*/
enum Logger_Level {
Debug = 0,
Info,
Warning,
Error,
Fatal
};
class Logger {
String Root_Folder_Path = "./";
String m_log_file_name;
String m_log_file_dir;
Logger_Level m_level = Logger_Level::Debug;
int log_m_count = 0,log_s_count = 5,log_size_count = 1;
CCQueue<String> m_log_s;
const char * Level_Count[5] = {"DEBUG", "INFO", "WARNING", "ERROR", "FATAL"};
bool log_flag = false;
int is_save_cond_ = 7;
Timer m_log_thread;
CCMutex _mutex_;
public:
Logger();
~Logger();
/**
*
* @param Folder
*/
void SetLogFolder(const String& Folder);
/**
*
* @param count
*/
void SetLogCount(int count);
/**
*
* @param count KB
*/
void SetLogSize(int count);
/**
*
* @param cond
*/
void SetLogSave(int cond);
/**
*
* @param level
*/
void SetLevel(Logger_Level level);
/**
* Debug等级
* @param fmt
*/
void Debug(const char* fmt,...);
/**
* Info等级
* @param fmt
*/
void Info(const char* fmt,...);
/**
* Warning等级
* @param fmt
*/
void Warning(const char* fmt,...);
/**
* Error等级
* @param fmt
*/
void Error(const char* fmt,...);
/**
* Fatal等级
* @param fmt
*/
void Fatal(const char* fmt,...);
/**
*
* @param level
* @param message
* @param file __FILE__
* @param line __LINE__
*/
void LogOutput(Logger_Level level, const String& message, const String& file= __FILE__, int line = __LINE__);
/**
* 线 12
*/
void Start();
/**
* 线
*/
void Stop();
private:
void Log2(Logger_Level level, const String& message);
bool LogWriting(const String& message);
void WriteData(const String& Path);
void LogThread();
void InitializeFolder();
void DeleteOldFolders(const String& rootPath, int days);
String GetLogFilePath(const String& fileName);
std::chrono::system_clock::time_point StringToDate(const String& dateString);
bool CompareDateDifference(const String& dateStr1, const String& dateStr2, int days);
String GetsTheCurrentLogFile();
void CloseWrite();
};
}
#define CC_Logger_Debug(LoggerObj,m) LoggerObj.LogOutput(CTL::Logger_Level::Debug,m, __FILE__, __LINE__)
#define CC_Logger_Info(LoggerObj,m) LoggerObj.LogOutput(CTL::Logger_Level::Info,m, __FILE__, __LINE__)
#define CC_Logger_Warning(LoggerObj,m) LoggerObj.LogOutput(CTL::Logger_Level::Warning,m, __FILE__, __LINE__)
#define CC_Logger_Error(LoggerObj,m) LoggerObj.LogOutput(CTL::Logger_Level::Error,m, __FILE__, __LINE__)
#define CC_Logger_Fatal(LoggerObj,m) LoggerObj.LogOutput(CTL::Logger_Level::Fatal,m, __FILE__, __LINE__)
#endif