Files
2026-02-01 22:23:06 +08:00

69 lines
1.4 KiB
C++

#ifndef __Logger_H__
#define __Logger_H__
#include <QString>
#include <QFile>
#include <QDateTime>
#include <QMutex>
/*
* 日志等级
*/
enum eLogLevel
{
eLL_Debug = 1, // 调试
eLL_Info = 2, // 普通信息
eLL_Warning = 3, // 警告
eLL_Error = 4, // 错误
};
class GLogger
{
protected:
GLogger();
public:
static GLogger* GetInstance();
static void FreeInstance();
virtual ~GLogger();
void SetDir(const QString& strDir);
void SetName(const QString& strName);
void SetWriteFlag(bool bWrite);
void SetLogLevel(eLogLevel elogLevel);
bool Open();
void Close();
bool WriteDebug(const QString& strMsg);
bool WriteInfo(const QString& strMsg);
bool WriteWaring(const QString& strMsg);
bool WriteError(const QString& strMsg);
private:
bool WriteMsg(const QString& strMsg);
bool IsNewDay();
public:
bool m_bOpen;
private:
bool m_bWrite;
QString m_strDir;
QString m_strName;
QFile m_varFile; //QFile不是线程安全的需枷锁
QDateTime m_varDateTime;
int m_nIndex;
eLogLevel m_eLogLevel;
QMutex m_mutexLocker;
static GLogger* m_ptrLogger;
};
#endif // __Logger_H__