diff options
Diffstat (limited to 'src/corelib/io/qloggingcategory.h')
-rw-r--r-- | src/corelib/io/qloggingcategory.h | 83 |
1 files changed, 60 insertions, 23 deletions
diff --git a/src/corelib/io/qloggingcategory.h b/src/corelib/io/qloggingcategory.h index 60773bd2a9..13b6cc17b8 100644 --- a/src/corelib/io/qloggingcategory.h +++ b/src/corelib/io/qloggingcategory.h @@ -19,17 +19,11 @@ public: bool isEnabled(QtMsgType type) const; void setEnabled(QtMsgType type, bool enable); -#ifdef Q_ATOMIC_INT8_IS_SUPPORTED bool isDebugEnabled() const { return bools.enabledDebug.loadRelaxed(); } bool isInfoEnabled() const { return bools.enabledInfo.loadRelaxed(); } bool isWarningEnabled() const { return bools.enabledWarning.loadRelaxed(); } bool isCriticalEnabled() const { return bools.enabledCritical.loadRelaxed(); } -#else - bool isDebugEnabled() const { return enabled.loadRelaxed() >> DebugShift & 1; } - bool isInfoEnabled() const { return enabled.loadRelaxed() >> InfoShift & 1; } - bool isWarningEnabled() const { return enabled.loadRelaxed() >> WarningShift & 1; } - bool isCriticalEnabled() const { return enabled.loadRelaxed() >> CriticalShift & 1; } -#endif + const char *categoryName() const { return name; } // allows usage of both factory method and variable in qCX macros @@ -49,19 +43,11 @@ private: Q_DECL_UNUSED_MEMBER void *d; // reserved for future use const char *name; -#ifdef Q_BIG_ENDIAN - enum { DebugShift = 0, WarningShift = 8, CriticalShift = 16, InfoShift = 24 }; -#else - enum { DebugShift = 24, WarningShift = 16, CriticalShift = 8, InfoShift = 0}; -#endif - struct AtomicBools { -#ifdef Q_ATOMIC_INT8_IS_SUPPORTED QBasicAtomicInteger<bool> enabledDebug; QBasicAtomicInteger<bool> enabledWarning; QBasicAtomicInteger<bool> enabledCritical; QBasicAtomicInteger<bool> enabledInfo; -#endif }; union { AtomicBools bools; @@ -81,11 +67,6 @@ template <QtMsgType Which> struct QLoggingCategoryMacroHolder if (IsOutputEnabled) init(cat); } - explicit QLoggingCategoryMacroHolder(QMessageLogger::CategoryFunction catfunc) - { - if (IsOutputEnabled) - init(catfunc()); - } void init(const QLoggingCategory &cat) noexcept { category = &cat; @@ -98,8 +79,12 @@ template <QtMsgType Which> struct QLoggingCategoryMacroHolder control = cat.isInfoEnabled(); } else if constexpr (Which == QtWarningMsg) { control = cat.isWarningEnabled(); - } else { + } else if constexpr (Which == QtCriticalMsg) { control = cat.isCriticalEnabled(); + } else if constexpr (Which == QtFatalMsg) { + control = true; + } else { + static_assert(QtPrivate::value_dependent_false<Which>(), "Unknown Qt message type"); } } const char *name() const { return category->categoryName(); } @@ -118,8 +103,55 @@ template <> const bool QLoggingCategoryMacroHolder<QtWarningMsg>::IsOutputEnable #endif } // unnamed namespace +#define QT_DECLARE_EXPORTED_QT_LOGGING_CATEGORY(name, export_macro) \ + namespace QtPrivateLogging { export_macro const QLoggingCategory &name(); } \ + using QtPrivateLogging::name; + +#if QT_BUILDING_QT +#define Q_DECLARE_LOGGING_CATEGORY(name) \ + namespace QtPrivateLogging { const QLoggingCategory &name(); } \ + using QtPrivateLogging::name; + +#define Q_DECLARE_EXPORTED_LOGGING_CATEGORY(name, export_macro) \ + namespace QtPrivateLogging { \ + Q_DECL_DEPRECATED_X("Use QT_DECLARE_EXPORTED_QT_LOGGING_CATEGORY in Qt") \ + export_macro const QLoggingCategory &name(); \ + } \ + using QtPrivateLogging::name; + +#define Q_LOGGING_CATEGORY_IMPL(name, ...) \ + const QLoggingCategory &name() \ + { \ + static const QLoggingCategory category(__VA_ARGS__); \ + return category; \ + } + +#if defined(Q_CC_GNU_ONLY) && Q_CC_GNU < 1000 +// GCC <10 thinks the "using" declaration from QT_DECLARE_EXPORTED_QT_LOGGING_CATEGORY +// or Q_DECLARE_LOGGING_CATEGORY conflicts with any weak overload created as part of the definition. +// So let's make it happy and repeat the "using" instead. +#define Q_LOGGING_CATEGORY(name, ...) \ + namespace QtPrivateLogging { Q_LOGGING_CATEGORY_IMPL(name, __VA_ARGS__) } \ + using QtPrivateLogging::name; +#else +#define Q_LOGGING_CATEGORY(name, ...) \ + namespace QtPrivateLogging { Q_LOGGING_CATEGORY_IMPL(name, __VA_ARGS__) } \ + Q_WEAK_OVERLOAD \ + Q_DECL_DEPRECATED_X("Use Q_STATIC_LOGGING_CATEGORY or add " \ + "either Q_DECLARE_LOGGING_CATEGORY or " \ + "QT_DECLARE_EXPORTED_QT_LOGGING_CATEGORY in a header") \ + const QLoggingCategory &name() { return QtPrivateLogging::name(); } +#endif + +#define Q_STATIC_LOGGING_CATEGORY(name, ...) \ + static Q_LOGGING_CATEGORY_IMPL(name, __VA_ARGS__) + +#else #define Q_DECLARE_LOGGING_CATEGORY(name) \ - extern const QLoggingCategory &name(); + const QLoggingCategory &name(); + +#define Q_DECLARE_EXPORTED_LOGGING_CATEGORY(name, export_macro) \ + export_macro Q_DECLARE_LOGGING_CATEGORY(name) #define Q_LOGGING_CATEGORY(name, ...) \ const QLoggingCategory &name() \ @@ -128,14 +160,19 @@ template <> const bool QLoggingCategoryMacroHolder<QtWarningMsg>::IsOutputEnable return category; \ } +#define Q_STATIC_LOGGING_CATEGORY(name, ...) \ + static Q_LOGGING_CATEGORY(name, __VA_ARGS__) +#endif + #define QT_MESSAGE_LOGGER_COMMON(category, level) \ - for (QLoggingCategoryMacroHolder<level> qt_category(category); qt_category; qt_category.control = false) \ + for (QLoggingCategoryMacroHolder<level> qt_category((category)()); qt_category; qt_category.control = false) \ QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC, qt_category.name()) #define qCDebug(category, ...) QT_MESSAGE_LOGGER_COMMON(category, QtDebugMsg).debug(__VA_ARGS__) #define qCInfo(category, ...) QT_MESSAGE_LOGGER_COMMON(category, QtInfoMsg).info(__VA_ARGS__) #define qCWarning(category, ...) QT_MESSAGE_LOGGER_COMMON(category, QtWarningMsg).warning(__VA_ARGS__) #define qCCritical(category, ...) QT_MESSAGE_LOGGER_COMMON(category, QtCriticalMsg).critical(__VA_ARGS__) +#define qCFatal(category, ...) QT_MESSAGE_LOGGER_COMMON(category, QtFatalMsg).fatal(__VA_ARGS__) QT_END_NAMESPACE |