Add option to suppress debug messages
Fixes: #177 Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
78638a3e23
commit
c75712d3f1
|
@ -36,6 +36,7 @@ option(FRAMELESSHELPER_BUILD_WIDGETS "Build FramelessHelper's Widgets module." O
|
|||
option(FRAMELESSHELPER_BUILD_QUICK "Build FramelessHelper's Quick module." ON)
|
||||
option(FRAMELESSHELPER_BUILD_EXAMPLES "Build FramelessHelper demo applications." ON)
|
||||
option(FRAMELESSHELPER_EXAMPLES_DEPLOYQT "Deploy the Qt framework after building the demo projects." ON)
|
||||
option(FRAMELESSHELPER_NO_DEBUG_OUTPUT "Suppress the debug messages from FramelessHelper." OFF)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
@ -163,4 +164,5 @@ message("Build the FramelessHelper::Widgets module: ${FRAMELESSHELPER_BUILD_WIDG
|
|||
message("Build the FramelessHelper::Quick module: ${FRAMELESSHELPER_BUILD_QUICK}")
|
||||
message("Build the FramelessHelper demo applications: ${FRAMELESSHELPER_BUILD_EXAMPLES}")
|
||||
message("Deploy Qt libraries after compilation: ${FRAMELESSHELPER_EXAMPLES_DEPLOYQT}")
|
||||
message("Suppress debug messages from FramelessHelper: ${FRAMELESSHELPER_NO_DEBUG_OUTPUT}")
|
||||
message("#######################################")
|
||||
|
|
|
@ -144,6 +144,12 @@ if(FRAMELESSHELPER_BUILD_STATIC)
|
|||
)
|
||||
endif()
|
||||
|
||||
if(FRAMELESSHELPER_NO_DEBUG_OUTPUT)
|
||||
target_compile_definitions(${SUB_PROJ_NAME} PRIVATE
|
||||
FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT
|
||||
)
|
||||
endif()
|
||||
|
||||
target_compile_definitions(${SUB_PROJ_NAME} PRIVATE
|
||||
QT_NO_KEYWORDS
|
||||
FRAMELESSHELPER_CORE_LIBRARY
|
||||
|
|
|
@ -94,15 +94,40 @@ FRAMELESSHELPER_BYTEARRAY_CONSTANT(xcb)
|
|||
[[maybe_unused]] static constexpr const char MAC_LAYER_ENV_VAR[] = "QT_MAC_WANTS_LAYER";
|
||||
#endif
|
||||
|
||||
FRAMELESSHELPER_STRING_CONSTANT2(FramelessHelperLogPrefix, "wangwenx190.framelesshelper.")
|
||||
|
||||
struct CoreData
|
||||
{
|
||||
QMutex mutex;
|
||||
QList<InitializeHookCallback> initHooks = {};
|
||||
QList<UninitializeHookCallback> uninitHooks = {};
|
||||
QLoggingCategory::CategoryFilter oldCategoryFilter = nullptr;
|
||||
};
|
||||
|
||||
Q_GLOBAL_STATIC(CoreData, coreData)
|
||||
|
||||
[[maybe_unused]] static inline void flhCategoryFilter(QLoggingCategory *category)
|
||||
{
|
||||
Q_ASSERT(category);
|
||||
if (!category) {
|
||||
return;
|
||||
}
|
||||
coreData()->mutex.lock();
|
||||
if (coreData()->oldCategoryFilter) {
|
||||
coreData()->oldCategoryFilter(category);
|
||||
}
|
||||
coreData()->mutex.unlock();
|
||||
const QString categoryName = QUtf8String(category->categoryName());
|
||||
if (!categoryName.isEmpty()
|
||||
&& categoryName.startsWith(kFramelessHelperLogPrefix, Qt::CaseInsensitive)) {
|
||||
category->setEnabled(QtInfoMsg, false);
|
||||
category->setEnabled(QtDebugMsg, false);
|
||||
category->setEnabled(QtWarningMsg, false);
|
||||
category->setEnabled(QtCriticalMsg, false);
|
||||
// QtFatalMsg cannot be changed; it will always remain true.
|
||||
}
|
||||
}
|
||||
|
||||
namespace FramelessHelper::Core
|
||||
{
|
||||
|
||||
|
@ -114,6 +139,12 @@ void initialize()
|
|||
}
|
||||
inited = true;
|
||||
|
||||
#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT
|
||||
coreData()->mutex.lock();
|
||||
coreData()->oldCategoryFilter = QLoggingCategory::installFilter(flhCategoryFilter);
|
||||
coreData()->mutex.unlock();
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
gtk_init(nullptr, nullptr);
|
||||
#endif
|
||||
|
|
|
@ -106,7 +106,7 @@ template<typename T>
|
|||
return {};
|
||||
}
|
||||
const auto propertyValue = gtkSetting<gchararray>(propertyName);
|
||||
const QString result = QString::fromUtf8(propertyValue);
|
||||
const QString result = QUtf8String(propertyValue);
|
||||
g_free(propertyValue);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -156,6 +156,12 @@ if(FRAMELESSHELPER_BUILD_STATIC)
|
|||
)
|
||||
endif()
|
||||
|
||||
if(FRAMELESSHELPER_NO_DEBUG_OUTPUT)
|
||||
target_compile_definitions(${SUB_PROJ_NAME} PRIVATE
|
||||
FRAMELESSHELPER_QUICK_NO_DEBUG_OUTPUT
|
||||
)
|
||||
endif()
|
||||
|
||||
target_compile_definitions(${SUB_PROJ_NAME} PRIVATE
|
||||
FRAMELESSHELPER_QUICK_LIBRARY
|
||||
)
|
||||
|
|
|
@ -95,6 +95,12 @@ if(FRAMELESSHELPER_BUILD_STATIC)
|
|||
)
|
||||
endif()
|
||||
|
||||
if(FRAMELESSHELPER_NO_DEBUG_OUTPUT)
|
||||
target_compile_definitions(${SUB_PROJ_NAME} PRIVATE
|
||||
FRAMELESSHELPER_WIDGETS_NO_DEBUG_OUTPUT
|
||||
)
|
||||
endif()
|
||||
|
||||
target_compile_definitions(${SUB_PROJ_NAME} PRIVATE
|
||||
QT_NO_KEYWORDS
|
||||
FRAMELESSHELPER_WIDGETS_LIBRARY
|
||||
|
|
Loading…
Reference in New Issue