This commit is contained in:
zhuzichu 2023-12-07 11:51:59 +08:00
parent 1abbc4593a
commit c80689e376
2 changed files with 30 additions and 20 deletions

View File

@ -25,6 +25,12 @@ if(NOT FLUENTUI_QML_PLUGIN_DIRECTORY)
endif() endif()
add_subdirectory(src) add_subdirectory(src)
target_compile_definitions(fluentuiplugin
PRIVATE
QT_MESSAGELOGCONTEXT
)
add_subdirectory(3rdparty/zxing-cpp) add_subdirectory(3rdparty/zxing-cpp)
if (FLUENTUI_BUILD_EXAMPLES) if (FLUENTUI_BUILD_EXAMPLES)

View File

@ -7,6 +7,7 @@
#include <QDateTime> #include <QDateTime>
#include <QStandardPaths> #include <QStandardPaths>
#include <QDir> #include <QDir>
#include <QThread>
#include "Version.h" #include "Version.h"
#ifdef WIN32 #ifdef WIN32
#include <process.h> #include <process.h>
@ -45,20 +46,7 @@ static inline void myMessageHandler(const QtMsgType type, const QMessageLogConte
if(logLevelMap[type]>g_logLevel){ if(logLevelMap[type]>g_logLevel){
return; return;
} }
if (context.file && !message.isEmpty()) { if (!message.isEmpty()) {
std::string strFileTmp = context.file;
const char* ptr = strrchr(strFileTmp.c_str(), '/');
if (nullptr != ptr) {
char fn[512] = {0};
sprintf(fn, "%s", ptr + 1);
strFileTmp = fn;
}
const char* ptrTmp = strrchr(strFileTmp.c_str(), '\\');
if (nullptr != ptrTmp) {
char fn[512] = {0};
sprintf(fn, "%s", ptrTmp + 1);
strFileTmp = fn;
}
QString levelName; QString levelName;
switch (type) { switch (type) {
case QtDebugMsg: case QtDebugMsg:
@ -77,13 +65,29 @@ static inline void myMessageHandler(const QtMsgType type, const QMessageLogConte
levelName = QStringLiteral("Fatal"); levelName = QStringLiteral("Fatal");
break; break;
} }
const QString finalMessage = QString::fromStdString("[%1] <%2> [ %3:%4 ] %5").arg( QString fileAndLineLogStr;
if(context.file){
std::string strFileTmp = context.file;
const char* ptr = strrchr(strFileTmp.c_str(), '/');
if (nullptr != ptr) {
char fn[512] = {0};
sprintf(fn, "%s", ptr + 1);
strFileTmp = fn;
}
const char* ptrTmp = strrchr(strFileTmp.c_str(), '\\');
if (nullptr != ptrTmp) {
char fn[512] = {0};
sprintf(fn, "%s", ptrTmp + 1);
strFileTmp = fn;
}
fileAndLineLogStr = QString::fromStdString("[%1:%2]").arg(QString::fromStdString(strFileTmp),QString::number(context.line));
}
const QString finalMessage = QString::fromStdString("%1[%2]%3[%4]:%5").arg(
QDateTime::currentDateTime().toString("yyyy/MM/dd hh:mm:ss.zzz"), QDateTime::currentDateTime().toString("yyyy/MM/dd hh:mm:ss.zzz"),
levelName, levelName,
QString::fromStdString(strFileTmp), fileAndLineLogStr,
QString::number(context.line), QString::number(reinterpret_cast<quintptr>(QThread::currentThreadId())),
message message);
);
if ((type == QtInfoMsg) || (type == QtDebugMsg)) { if ((type == QtInfoMsg) || (type == QtDebugMsg)) {
std::cout << qPrintable(finalMessage) << std::endl; std::cout << qPrintable(finalMessage) << std::endl;
} else { } else {
@ -131,7 +135,7 @@ void Log::setup(const QString &app)
g_file_path = logDir.filePath(logFileName); g_file_path = logDir.filePath(logFileName);
qInstallMessageHandler(myMessageHandler); qInstallMessageHandler(myMessageHandler);
qInfo()<<"==================================================="; qInfo()<<"===================================================";
qInfo()<<"[AppName]"<<"FluentUI Example"; qInfo()<<"[AppName]"<<g_app;
qInfo()<<"[AppVersion]"<<APPLICATION_VERSION; qInfo()<<"[AppVersion]"<<APPLICATION_VERSION;
#ifdef WIN32 #ifdef WIN32
qInfo()<<"[ProcessId]"<<QString::number(_getpid()); qInfo()<<"[ProcessId]"<<QString::number(_getpid());