Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
use better solution to disable logging
Browse files Browse the repository at this point in the history
Thank very much to @SineStriker !

Fixes: #181

Signed-off-by: Yuhang Zhao <[email protected]>
  • Loading branch information
wangwenx190 committed Nov 10, 2022
1 parent b8a3ff6 commit 70a7182
Show file tree
Hide file tree
Showing 32 changed files with 384 additions and 158 deletions.
16 changes: 12 additions & 4 deletions src/core/chromepalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,18 @@
FRAMELESSHELPER_BEGIN_NAMESPACE

Q_LOGGING_CATEGORY(lcChromePalette, "wangwenx190.framelesshelper.core.chromepalette")
#define INFO qCInfo(lcChromePalette)
#define DEBUG qCDebug(lcChromePalette)
#define WARNING qCWarning(lcChromePalette)
#define CRITICAL qCCritical(lcChromePalette)

#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT
# define INFO QT_NO_QDEBUG_MACRO()
# define DEBUG QT_NO_QDEBUG_MACRO()
# define WARNING QT_NO_QDEBUG_MACRO()
# define CRITICAL QT_NO_QDEBUG_MACRO()
#else
# define INFO qCInfo(lcChromePalette)
# define DEBUG qCDebug(lcChromePalette)
# define WARNING qCWarning(lcChromePalette)
# define CRITICAL qCCritical(lcChromePalette)
#endif

using namespace Global;

Expand Down
16 changes: 12 additions & 4 deletions src/core/framelessconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,18 @@
FRAMELESSHELPER_BEGIN_NAMESPACE

Q_LOGGING_CATEGORY(lcFramelessConfig, "wangwenx190.framelesshelper.core.framelessconfig")
#define INFO qCInfo(lcFramelessConfig)
#define DEBUG qCDebug(lcFramelessConfig)
#define WARNING qCWarning(lcFramelessConfig)
#define CRITICAL qCCritical(lcFramelessConfig)

#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT
# define INFO QT_NO_QDEBUG_MACRO()
# define DEBUG QT_NO_QDEBUG_MACRO()
# define WARNING QT_NO_QDEBUG_MACRO()
# define CRITICAL QT_NO_QDEBUG_MACRO()
#else
# define INFO qCInfo(lcFramelessConfig)
# define DEBUG qCDebug(lcFramelessConfig)
# define WARNING qCWarning(lcFramelessConfig)
# define CRITICAL qCCritical(lcFramelessConfig)
#endif

using namespace Global;

Expand Down
16 changes: 12 additions & 4 deletions src/core/framelesshelper_qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,18 @@
FRAMELESSHELPER_BEGIN_NAMESPACE

Q_LOGGING_CATEGORY(lcFramelessHelperQt, "wangwenx190.framelesshelper.core.impl.qt")
#define INFO qCInfo(lcFramelessHelperQt)
#define DEBUG qCDebug(lcFramelessHelperQt)
#define WARNING qCWarning(lcFramelessHelperQt)
#define CRITICAL qCCritical(lcFramelessHelperQt)

#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT
# define INFO QT_NO_QDEBUG_MACRO()
# define DEBUG QT_NO_QDEBUG_MACRO()
# define WARNING QT_NO_QDEBUG_MACRO()
# define CRITICAL QT_NO_QDEBUG_MACRO()
#else
# define INFO qCInfo(lcFramelessHelperQt)
# define DEBUG qCDebug(lcFramelessHelperQt)
# define WARNING qCWarning(lcFramelessHelperQt)
# define CRITICAL qCCritical(lcFramelessHelperQt)
#endif

using namespace Global;

Expand Down
16 changes: 12 additions & 4 deletions src/core/framelesshelper_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,18 @@
FRAMELESSHELPER_BEGIN_NAMESPACE

Q_LOGGING_CATEGORY(lcFramelessHelperWin, "wangwenx190.framelesshelper.core.impl.win")
#define INFO qCInfo(lcFramelessHelperWin)
#define DEBUG qCDebug(lcFramelessHelperWin)
#define WARNING qCWarning(lcFramelessHelperWin)
#define CRITICAL qCCritical(lcFramelessHelperWin)

#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT
# define INFO QT_NO_QDEBUG_MACRO()
# define DEBUG QT_NO_QDEBUG_MACRO()
# define WARNING QT_NO_QDEBUG_MACRO()
# define CRITICAL QT_NO_QDEBUG_MACRO()
#else
# define INFO qCInfo(lcFramelessHelperWin)
# define DEBUG qCDebug(lcFramelessHelperWin)
# define WARNING qCWarning(lcFramelessHelperWin)
# define CRITICAL qCCritical(lcFramelessHelperWin)
#endif

using namespace Global;

Expand Down
46 changes: 12 additions & 34 deletions src/core/framelesshelpercore_global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,18 @@
FRAMELESSHELPER_BEGIN_NAMESPACE

Q_LOGGING_CATEGORY(lcCoreGlobal, "wangwenx190.framelesshelper.core.global")
#define INFO qCInfo(lcCoreGlobal)
#define DEBUG qCDebug(lcCoreGlobal)
#define WARNING qCWarning(lcCoreGlobal)
#define CRITICAL qCCritical(lcCoreGlobal)

#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT
# define INFO QT_NO_QDEBUG_MACRO()
# define DEBUG QT_NO_QDEBUG_MACRO()
# define WARNING QT_NO_QDEBUG_MACRO()
# define CRITICAL QT_NO_QDEBUG_MACRO()
#else
# define INFO qCInfo(lcCoreGlobal)
# define DEBUG qCDebug(lcCoreGlobal)
# define WARNING qCWarning(lcCoreGlobal)
# define CRITICAL qCCritical(lcCoreGlobal)
#endif

using namespace Global;

Expand All @@ -96,40 +104,16 @@ FRAMELESSHELPER_BYTEARRAY_CONSTANT(xcb)
#endif

[[maybe_unused]] static constexpr const char kNoLogoEnvVar[] = "FRAMELESSHELPER_NO_LOGO";
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
{

Expand All @@ -141,12 +125,6 @@ void initialize()
}
inited = true;

#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT
coreData()->mutex.lock();
coreData()->oldCategoryFilter = QLoggingCategory::installFilter(flhCategoryFilter);
coreData()->mutex.unlock();
#endif

outputLogo();

#ifdef Q_OS_LINUX
Expand Down
16 changes: 12 additions & 4 deletions src/core/framelessmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,18 @@ static inline void initResource()
FRAMELESSHELPER_BEGIN_NAMESPACE

Q_LOGGING_CATEGORY(lcFramelessManager, "wangwenx190.framelesshelper.core.framelessmanager")
#define INFO qCInfo(lcFramelessManager)
#define DEBUG qCDebug(lcFramelessManager)
#define WARNING qCWarning(lcFramelessManager)
#define CRITICAL qCCritical(lcFramelessManager)

#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT
# define INFO QT_NO_QDEBUG_MACRO()
# define DEBUG QT_NO_QDEBUG_MACRO()
# define WARNING QT_NO_QDEBUG_MACRO()
# define CRITICAL QT_NO_QDEBUG_MACRO()
#else
# define INFO qCInfo(lcFramelessManager)
# define DEBUG qCDebug(lcFramelessManager)
# define WARNING qCWarning(lcFramelessManager)
# define CRITICAL qCCritical(lcFramelessManager)
#endif

using namespace Global;

Expand Down
16 changes: 12 additions & 4 deletions src/core/micamaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,18 @@ static inline void initResource()
FRAMELESSHELPER_BEGIN_NAMESPACE

Q_LOGGING_CATEGORY(lcMicaMaterial, "wangwenx190.framelesshelper.core.micamaterial")
#define INFO qCInfo(lcMicaMaterial)
#define DEBUG qCDebug(lcMicaMaterial)
#define WARNING qCWarning(lcMicaMaterial)
#define CRITICAL qCCritical(lcMicaMaterial)

#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT
# define INFO QT_NO_QDEBUG_MACRO()
# define DEBUG QT_NO_QDEBUG_MACRO()
# define WARNING QT_NO_QDEBUG_MACRO()
# define CRITICAL QT_NO_QDEBUG_MACRO()
#else
# define INFO qCInfo(lcMicaMaterial)
# define DEBUG qCDebug(lcMicaMaterial)
# define WARNING qCWarning(lcMicaMaterial)
# define CRITICAL qCCritical(lcMicaMaterial)
#endif

using namespace Global;

Expand Down
16 changes: 12 additions & 4 deletions src/core/registrykey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,18 @@
FRAMELESSHELPER_BEGIN_NAMESPACE

Q_LOGGING_CATEGORY(lcCoreRegistryKey, "wangwenx190.framelesshelper.core.registrykey")
#define INFO qCInfo(lcCoreRegistryKey)
#define DEBUG qCDebug(lcCoreRegistryKey)
#define WARNING qCWarning(lcCoreRegistryKey)
#define CRITICAL qCCritical(lcCoreRegistryKey)

#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT
# define INFO QT_NO_QDEBUG_MACRO()
# define DEBUG QT_NO_QDEBUG_MACRO()
# define WARNING QT_NO_QDEBUG_MACRO()
# define CRITICAL QT_NO_QDEBUG_MACRO()
#else
# define INFO qCInfo(lcCoreRegistryKey)
# define DEBUG qCDebug(lcCoreRegistryKey)
# define WARNING qCWarning(lcCoreRegistryKey)
# define CRITICAL qCCritical(lcCoreRegistryKey)
#endif

using namespace Global;

Expand Down
16 changes: 12 additions & 4 deletions src/core/sysapiloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,18 @@
FRAMELESSHELPER_BEGIN_NAMESPACE

Q_LOGGING_CATEGORY(lcSysApiLoader, "wangwenx190.framelesshelper.core.sysapiloader")
#define INFO qCInfo(lcSysApiLoader)
#define DEBUG qCDebug(lcSysApiLoader)
#define WARNING qCWarning(lcSysApiLoader)
#define CRITICAL qCCritical(lcSysApiLoader)

#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT
# define INFO QT_NO_QDEBUG_MACRO()
# define DEBUG QT_NO_QDEBUG_MACRO()
# define WARNING QT_NO_QDEBUG_MACRO()
# define CRITICAL QT_NO_QDEBUG_MACRO()
#else
# define INFO qCInfo(lcSysApiLoader)
# define DEBUG qCDebug(lcSysApiLoader)
# define WARNING qCWarning(lcSysApiLoader)
# define CRITICAL qCCritical(lcSysApiLoader)
#endif

struct SysApiLoaderData
{
Expand Down
16 changes: 12 additions & 4 deletions src/core/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,18 @@
FRAMELESSHELPER_BEGIN_NAMESPACE

Q_LOGGING_CATEGORY(lcUtilsCommon, "wangwenx190.framelesshelper.core.utils.common")
#define INFO qCInfo(lcUtilsCommon)
#define DEBUG qCDebug(lcUtilsCommon)
#define WARNING qCWarning(lcUtilsCommon)
#define CRITICAL qCCritical(lcUtilsCommon)

#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT
# define INFO QT_NO_QDEBUG_MACRO()
# define DEBUG QT_NO_QDEBUG_MACRO()
# define WARNING QT_NO_QDEBUG_MACRO()
# define CRITICAL QT_NO_QDEBUG_MACRO()
#else
# define INFO qCInfo(lcUtilsCommon)
# define DEBUG qCDebug(lcUtilsCommon)
# define WARNING qCWarning(lcUtilsCommon)
# define CRITICAL qCCritical(lcUtilsCommon)
#endif

using namespace Global;

Expand Down
16 changes: 12 additions & 4 deletions src/core/utils_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,10 +575,18 @@ Q_DECLARE_METATYPE(QMargins)
FRAMELESSHELPER_BEGIN_NAMESPACE

Q_LOGGING_CATEGORY(lcUtilsWin, "wangwenx190.framelesshelper.core.utils.win")
#define INFO qCInfo(lcUtilsWin)
#define DEBUG qCDebug(lcUtilsWin)
#define WARNING qCWarning(lcUtilsWin)
#define CRITICAL qCCritical(lcUtilsWin)

#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT
# define INFO QT_NO_QDEBUG_MACRO()
# define DEBUG QT_NO_QDEBUG_MACRO()
# define WARNING QT_NO_QDEBUG_MACRO()
# define CRITICAL QT_NO_QDEBUG_MACRO()
#else
# define INFO qCInfo(lcUtilsWin)
# define DEBUG qCDebug(lcUtilsWin)
# define WARNING qCWarning(lcUtilsWin)
# define CRITICAL qCCritical(lcUtilsWin)
#endif

using namespace Global;

Expand Down
16 changes: 12 additions & 4 deletions src/core/windowborderpainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,18 @@
FRAMELESSHELPER_BEGIN_NAMESPACE

Q_LOGGING_CATEGORY(lcWindowBorderPainter, "wangwenx190.framelesshelper.core.windowborderpainter")
#define INFO qCInfo(lcWindowBorderPainter)
#define DEBUG qCDebug(lcWindowBorderPainter)
#define WARNING qCWarning(lcWindowBorderPainter)
#define CRITICAL qCCritical(lcWindowBorderPainter)

#ifdef FRAMELESSHELPER_CORE_NO_DEBUG_OUTPUT
# define INFO QT_NO_QDEBUG_MACRO()
# define DEBUG QT_NO_QDEBUG_MACRO()
# define WARNING QT_NO_QDEBUG_MACRO()
# define CRITICAL QT_NO_QDEBUG_MACRO()
#else
# define INFO qCInfo(lcWindowBorderPainter)
# define DEBUG qCDebug(lcWindowBorderPainter)
# define WARNING qCWarning(lcWindowBorderPainter)
# define CRITICAL qCCritical(lcWindowBorderPainter)
#endif

using namespace Global;

Expand Down
16 changes: 12 additions & 4 deletions src/quick/framelesshelperquick_global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,18 @@
FRAMELESSHELPER_BEGIN_NAMESPACE

Q_LOGGING_CATEGORY(lcQuickGlobal, "wangwenx190.framelesshelper.quick.global")
#define INFO qCInfo(lcQuickGlobal)
#define DEBUG qCDebug(lcQuickGlobal)
#define WARNING qCWarning(lcQuickGlobal)
#define CRITICAL qCCritical(lcQuickGlobal)

#ifdef FRAMELESSHELPER_QUICK_NO_DEBUG_OUTPUT
# define INFO QT_NO_QDEBUG_MACRO()
# define DEBUG QT_NO_QDEBUG_MACRO()
# define WARNING QT_NO_QDEBUG_MACRO()
# define CRITICAL QT_NO_QDEBUG_MACRO()
#else
# define INFO qCInfo(lcQuickGlobal)
# define DEBUG qCDebug(lcQuickGlobal)
# define WARNING qCWarning(lcQuickGlobal)
# define CRITICAL qCCritical(lcQuickGlobal)
#endif

QuickGlobal::QuickGlobal(QObject *parent) : QObject(parent)
{
Expand Down
16 changes: 12 additions & 4 deletions src/quick/framelessquickapplicationwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,18 @@
FRAMELESSHELPER_BEGIN_NAMESPACE

Q_LOGGING_CATEGORY(lcFramelessQuickApplicationWindow, "wangwenx190.framelesshelper.quick.framelessquickapplicationwindow")
#define INFO qCInfo(lcFramelessQuickApplicationWindow)
#define DEBUG qCDebug(lcFramelessQuickApplicationWindow)
#define WARNING qCWarning(lcFramelessQuickApplicationWindow)
#define CRITICAL qCCritical(lcFramelessQuickApplicationWindow)

#ifdef FRAMELESSHELPER_QUICK_NO_DEBUG_OUTPUT
# define INFO QT_NO_QDEBUG_MACRO()
# define DEBUG QT_NO_QDEBUG_MACRO()
# define WARNING QT_NO_QDEBUG_MACRO()
# define CRITICAL QT_NO_QDEBUG_MACRO()
#else
# define INFO qCInfo(lcFramelessQuickApplicationWindow)
# define DEBUG qCDebug(lcFramelessQuickApplicationWindow)
# define WARNING qCWarning(lcFramelessQuickApplicationWindow)
# define CRITICAL qCCritical(lcFramelessQuickApplicationWindow)
#endif

using namespace Global;

Expand Down
16 changes: 12 additions & 4 deletions src/quick/framelessquickhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,18 @@
FRAMELESSHELPER_BEGIN_NAMESPACE

Q_LOGGING_CATEGORY(lcFramelessQuickHelper, "wangwenx190.framelesshelper.quick.framelessquickhelper")
#define INFO qCInfo(lcFramelessQuickHelper)
#define DEBUG qCDebug(lcFramelessQuickHelper)
#define WARNING qCWarning(lcFramelessQuickHelper)
#define CRITICAL qCCritical(lcFramelessQuickHelper)

#ifdef FRAMELESSHELPER_QUICK_NO_DEBUG_OUTPUT
# define INFO QT_NO_QDEBUG_MACRO()
# define DEBUG QT_NO_QDEBUG_MACRO()
# define WARNING QT_NO_QDEBUG_MACRO()
# define CRITICAL QT_NO_QDEBUG_MACRO()
#else
# define INFO qCInfo(lcFramelessQuickHelper)
# define DEBUG qCDebug(lcFramelessQuickHelper)
# define WARNING qCWarning(lcFramelessQuickHelper)
# define CRITICAL qCCritical(lcFramelessQuickHelper)
#endif

using namespace Global;

Expand Down
Loading

0 comments on commit 70a7182

Please sign in to comment.