Files
Lixinzhe_lib/Log/LogL.h

99 lines
2.1 KiB
C
Raw Normal View History

2025-06-16 08:52:40 +08:00
#ifndef LXZL_LOGL_H
#define LXZL_LOGL_H
/**
*
* udptcp
*/
#include "UDP.h"
#include <string>
#include <thread>
#include <queue>
#include <mutex>
#include <condition_variable>
enum LogType{
LTStd,//日志输出到控制台
LTTxt,//日志输出到文本文件
LTUdp,//日志输出到UDP
LTTcp,//日志输出到TCP
};
enum LogLevel{
LLDebug,//调试
LLInfo,//一般
LLWarn,//警告
LLError,//错误
};
class LogL {
public:
/**
*
* @param logType
* @param isSync true/false
* @param logPath (LTStd:;LTTxt:;LTUdp:ip端口)
*/
explicit LogL(LogType logType, bool isSync = true, std::string logPath = "");
~LogL();
/**
*
* @param str
*/
void debug(const std::string &str);
void info(const std::string &str);
void warn(const std::string &str);
void error(const std::string &str);
private:
void logThread();
void log(const std::string &str, LogLevel level);
private:
std::thread *m_thread;
bool m_thread_run;
bool m_isSync;//是否同步
LogType m_logType;//输出类型
std::string m_logPath;//输出地址
std::queue<std::string> m_log_queue;//日志容器
std::mutex m_mtx;
std::condition_variable m_cond_empty;//空时停止
std::condition_variable m_cond_full;//满时停止
std::ofstream *m_file;
int32_t m_today;
UDPSender *m_sender;
};
/**
*
* @param path
* @return bool是否创建成功
*/
bool myMkdir(const char *path);
/**
*
*/
class myDateTime {
public:
myDateTime();
int32_t year;
int32_t month;
int32_t day;
int32_t hour;
int32_t minute;
int32_t second;
std::string toDate() const;
std::string toTime() const;
std::string toDateTime() const;
};
#endif //LXZL_LOGL_H