mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2024-11-27 05:38:37 +08:00
add log level
This commit is contained in:
parent
c1ffce06aa
commit
1abbc4593a
@ -29,8 +29,22 @@ static bool g_logError = false;
|
|||||||
static std::unique_ptr<QFile> g_logFile = nullptr;
|
static std::unique_ptr<QFile> g_logFile = nullptr;
|
||||||
static std::unique_ptr<QTextStream> g_logStream = nullptr;
|
static std::unique_ptr<QTextStream> g_logStream = nullptr;
|
||||||
|
|
||||||
|
static int g_logLevel = 4;
|
||||||
|
|
||||||
|
std::map<QtMsgType, int> logLevelMap = {
|
||||||
|
{QtFatalMsg,0},
|
||||||
|
{QtCriticalMsg,1},
|
||||||
|
{QtWarningMsg,2},
|
||||||
|
{QtInfoMsg,3},
|
||||||
|
{QtDebugMsg,4}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
static inline void myMessageHandler(const QtMsgType type, const QMessageLogContext &context, const QString &message)
|
static inline void myMessageHandler(const QtMsgType type, const QMessageLogContext &context, const QString &message)
|
||||||
{
|
{
|
||||||
|
if(logLevelMap[type]>g_logLevel){
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (context.file && !message.isEmpty()) {
|
if (context.file && !message.isEmpty()) {
|
||||||
std::string strFileTmp = context.file;
|
std::string strFileTmp = context.file;
|
||||||
const char* ptr = strrchr(strFileTmp.c_str(), '/');
|
const char* ptr = strrchr(strFileTmp.c_str(), '/');
|
||||||
@ -116,9 +130,8 @@ void Log::setup(const QString &app)
|
|||||||
}
|
}
|
||||||
g_file_path = logDir.filePath(logFileName);
|
g_file_path = logDir.filePath(logFileName);
|
||||||
qInstallMessageHandler(myMessageHandler);
|
qInstallMessageHandler(myMessageHandler);
|
||||||
qDebug()<<logDirPath;
|
|
||||||
qInfo()<<"===================================================";
|
qInfo()<<"===================================================";
|
||||||
qInfo()<<"[AppName] FluentUI Example";
|
qInfo()<<"[AppName]"<<"FluentUI Example";
|
||||||
qInfo()<<"[AppVersion]"<<APPLICATION_VERSION;
|
qInfo()<<"[AppVersion]"<<APPLICATION_VERSION;
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
qInfo()<<"[ProcessId]"<<QString::number(_getpid());
|
qInfo()<<"[ProcessId]"<<QString::number(_getpid());
|
||||||
@ -130,6 +143,7 @@ void Log::setup(const QString &app)
|
|||||||
qInfo()<<" [DeviceId]"<<QSysInfo::machineUniqueId();
|
qInfo()<<" [DeviceId]"<<QSysInfo::machineUniqueId();
|
||||||
qInfo()<<" [Manufacturer]"<<QSysInfo::prettyProductName();
|
qInfo()<<" [Manufacturer]"<<QSysInfo::prettyProductName();
|
||||||
qInfo()<<" [CPU_ABI]"<<QSysInfo::currentCpuArchitecture();
|
qInfo()<<" [CPU_ABI]"<<QSysInfo::currentCpuArchitecture();
|
||||||
|
qInfo()<<"[LOG_LEVEL]"<<g_logLevel;
|
||||||
qInfo()<<"[LOG_PATH]"<<g_file_path;
|
qInfo()<<"[LOG_PATH]"<<g_file_path;
|
||||||
qInfo()<<"===================================================";
|
qInfo()<<"===================================================";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user