From c80689e376d3acd9b79e8229483360ee32c377ab Mon Sep 17 00:00:00 2001 From: zhuzichu Date: Thu, 7 Dec 2023 11:51:59 +0800 Subject: [PATCH] update --- CMakeLists.txt | 6 ++++++ example/src/helper/Log.cpp | 44 +++++++++++++++++++++----------------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e8102887..cd253704 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,12 @@ if(NOT FLUENTUI_QML_PLUGIN_DIRECTORY) endif() add_subdirectory(src) + +target_compile_definitions(fluentuiplugin + PRIVATE + QT_MESSAGELOGCONTEXT +) + add_subdirectory(3rdparty/zxing-cpp) if (FLUENTUI_BUILD_EXAMPLES) diff --git a/example/src/helper/Log.cpp b/example/src/helper/Log.cpp index ba98deec..c53236e3 100644 --- a/example/src/helper/Log.cpp +++ b/example/src/helper/Log.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "Version.h" #ifdef WIN32 #include @@ -45,20 +46,7 @@ static inline void myMessageHandler(const QtMsgType type, const QMessageLogConte if(logLevelMap[type]>g_logLevel){ return; } - if (context.file && !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; - } + if (!message.isEmpty()) { QString levelName; switch (type) { case QtDebugMsg: @@ -77,13 +65,29 @@ static inline void myMessageHandler(const QtMsgType type, const QMessageLogConte levelName = QStringLiteral("Fatal"); 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"), levelName, - QString::fromStdString(strFileTmp), - QString::number(context.line), - message - ); + fileAndLineLogStr, + QString::number(reinterpret_cast(QThread::currentThreadId())), + message); if ((type == QtInfoMsg) || (type == QtDebugMsg)) { std::cout << qPrintable(finalMessage) << std::endl; } else { @@ -131,7 +135,7 @@ void Log::setup(const QString &app) g_file_path = logDir.filePath(logFileName); qInstallMessageHandler(myMessageHandler); qInfo()<<"==================================================="; - qInfo()<<"[AppName]"<<"FluentUI Example"; + qInfo()<<"[AppName]"<