diff options
author | Ulf Hermann <[email protected]> | 2024-06-03 09:00:18 +0200 |
---|---|---|
committer | Ulf Hermann <[email protected]> | 2024-06-05 11:36:49 +0200 |
commit | 374a2b0c5fe8b4a6c52f39a20075f1282ce76b96 (patch) | |
tree | 78ca510bebac98aedf6b75c1b1db4894e62b1cf3 | |
parent | f6bb8f832442a2e70b3d4718fb06807cfe98511b (diff) |
Logging: Add a macro for static logging category
Since name clashes between logging categories are so common, having a
way to explicitly avoid them is important. So far, we are depending on
internals of Q_LOGGING_CATEGORY to place the "static" in the right
location. That's less than ideal.
Task-number: QTBUG-67692
Change-Id: Ifeda5297d1d1220a57118b3bf7c7310e4ddd4f93
Reviewed-by: Tor Arne Vestbø <[email protected]>
Reviewed-by: Thiago Macieira <[email protected]>
-rw-r--r-- | src/corelib/io/qloggingcategory.cpp | 39 | ||||
-rw-r--r-- | src/corelib/io/qloggingcategory.h | 3 | ||||
-rw-r--r-- | src/corelib/io/qloggingregistry_p.h | 3 | ||||
-rw-r--r-- | src/corelib/plugin/qelfparser_p.cpp | 2 | ||||
-rw-r--r-- | src/corelib/plugin/qfactoryloader.cpp | 2 | ||||
-rw-r--r-- | src/corelib/plugin/qlibrary.cpp | 2 | ||||
-rw-r--r-- | src/network/kernel/qdnslookup.cpp | 2 | ||||
-rw-r--r-- | src/plugins/sqldrivers/odbc/qsql_odbc.cpp | 2 | ||||
-rw-r--r-- | src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp | 2 | ||||
-rw-r--r-- | src/sql/kernel/qsqldatabase.cpp | 2 | ||||
-rw-r--r-- | src/sql/kernel/qsqlquery.cpp | 2 |
11 files changed, 53 insertions, 8 deletions
diff --git a/src/corelib/io/qloggingcategory.cpp b/src/corelib/io/qloggingcategory.cpp index 10763dd65a9..4e28c44e7b9 100644 --- a/src/corelib/io/qloggingcategory.cpp +++ b/src/corelib/io/qloggingcategory.cpp @@ -665,4 +665,43 @@ void QLoggingCategory::setFilterRules(const QString &rules) This macro must be used outside of a class or method. */ +/*! + \macro Q_STATIC_LOGGING_CATEGORY(name, string) + \sa Q_LOGGING_CATEGORY() + \relates QLoggingCategory + \since 6.9 + + Defines a static logging category \a name, and makes it configurable under + the \a string identifier. By default, all message types are enabled. + + The logging category is created using the \c static qualifier so that you + can only access it in the same translation unit. This avoids accidental + symbol clashes. + + The implicitly-defined QLoggingCategory object is created on first use, + in a thread-safe manner. + + This macro must be used outside of a class or method. +*/ + +/*! + \macro Q_STATIC_LOGGING_CATEGORY(name, string, msgType) + \sa Q_LOGGING_CATEGORY() + \relates QLoggingCategory + \since 6.9 + + Defines a static logging category \a name, and makes it configurable under + the \a string identifier. By default, messages of QtMsgType \a msgType and + more severe are enabled, types with a lower severity are disabled. + + The logging category is created using the \c static qualifier so that you + can only access it in the same translation unit. This avoids accidental + symbol clashes. + + The implicitly-defined QLoggingCategory object is created on first use, in + a thread-safe manner. + + This macro must be used outside of a class or method. +*/ + QT_END_NAMESPACE diff --git a/src/corelib/io/qloggingcategory.h b/src/corelib/io/qloggingcategory.h index 7c32beea1aa..b8be7f6037c 100644 --- a/src/corelib/io/qloggingcategory.h +++ b/src/corelib/io/qloggingcategory.h @@ -116,6 +116,9 @@ template <> const bool QLoggingCategoryMacroHolder<QtWarningMsg>::IsOutputEnable return category; \ } +#define Q_STATIC_LOGGING_CATEGORY(name, ...) \ + static Q_LOGGING_CATEGORY(name, __VA_ARGS__) + #define QT_MESSAGE_LOGGER_COMMON(category, level) \ 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()) diff --git a/src/corelib/io/qloggingregistry_p.h b/src/corelib/io/qloggingregistry_p.h index 92b96f0ba40..42738891f7f 100644 --- a/src/corelib/io/qloggingregistry_p.h +++ b/src/corelib/io/qloggingregistry_p.h @@ -39,6 +39,9 @@ QT_BEGIN_NAMESPACE return category; \ } +#define Q_STATIC_LOGGING_CATEGORY_WITH_ENV_OVERRIDE(name, env, categoryName) \ + static Q_LOGGING_CATEGORY_WITH_ENV_OVERRIDE(name, env, categoryName) + class Q_AUTOTEST_EXPORT QLoggingRule { public: diff --git a/src/corelib/plugin/qelfparser_p.cpp b/src/corelib/plugin/qelfparser_p.cpp index 7f6271cde49..78c9be0e563 100644 --- a/src/corelib/plugin/qelfparser_p.cpp +++ b/src/corelib/plugin/qelfparser_p.cpp @@ -35,7 +35,7 @@ static constexpr bool IncludeValidityChecks = true; # define QELFPARSER_DEBUG #endif #if defined(QELFPARSER_DEBUG) -static Q_LOGGING_CATEGORY(lcElfParser, "qt.core.plugin.elfparser") +Q_STATIC_LOGGING_CATEGORY(lcElfParser, "qt.core.plugin.elfparser") # define qEDebug qCDebug(lcElfParser) << reinterpret_cast<const char16_t *>(error.errMsg->constData()) << ':' #else # define qEDebug if (false) {} else QNoDebug() diff --git a/src/corelib/plugin/qfactoryloader.cpp b/src/corelib/plugin/qfactoryloader.cpp index e2d9a40cb4b..6486414d8c1 100644 --- a/src/corelib/plugin/qfactoryloader.cpp +++ b/src/corelib/plugin/qfactoryloader.cpp @@ -272,7 +272,7 @@ public: #if QT_CONFIG(library) -static Q_LOGGING_CATEGORY_WITH_ENV_OVERRIDE(lcFactoryLoader, "QT_DEBUG_PLUGINS", +Q_STATIC_LOGGING_CATEGORY_WITH_ENV_OVERRIDE(lcFactoryLoader, "QT_DEBUG_PLUGINS", "qt.core.plugin.factoryloader") namespace { diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp index a3ef8e3c525..8f1db7e4d40 100644 --- a/src/corelib/plugin/qlibrary.cpp +++ b/src/corelib/plugin/qlibrary.cpp @@ -55,7 +55,7 @@ static constexpr bool QtBuildIsDebug = true; #endif Q_LOGGING_CATEGORY_WITH_ENV_OVERRIDE(qt_lcDebugPlugins, "QT_DEBUG_PLUGINS", "qt.core.plugin.loader") -static Q_LOGGING_CATEGORY_WITH_ENV_OVERRIDE(lcDebugLibrary, "QT_DEBUG_PLUGINS", "qt.core.library") +Q_STATIC_LOGGING_CATEGORY_WITH_ENV_OVERRIDE(lcDebugLibrary, "QT_DEBUG_PLUGINS", "qt.core.library") /*! \class QLibrary diff --git a/src/network/kernel/qdnslookup.cpp b/src/network/kernel/qdnslookup.cpp index 1b4db7130b2..d8ac95b3ec9 100644 --- a/src/network/kernel/qdnslookup.cpp +++ b/src/network/kernel/qdnslookup.cpp @@ -24,7 +24,7 @@ QT_BEGIN_NAMESPACE using namespace Qt::StringLiterals; -static Q_LOGGING_CATEGORY(lcDnsLookup, "qt.network.dnslookup", QtCriticalMsg) +Q_STATIC_LOGGING_CATEGORY(lcDnsLookup, "qt.network.dnslookup", QtCriticalMsg) namespace { struct QDnsLookupThreadPool : QThreadPool diff --git a/src/plugins/sqldrivers/odbc/qsql_odbc.cpp b/src/plugins/sqldrivers/odbc/qsql_odbc.cpp index 976911d4583..77137f3b3c3 100644 --- a/src/plugins/sqldrivers/odbc/qsql_odbc.cpp +++ b/src/plugins/sqldrivers/odbc/qsql_odbc.cpp @@ -27,7 +27,7 @@ QT_BEGIN_NAMESPACE -static Q_LOGGING_CATEGORY(lcOdbc, "qt.sql.odbc") +Q_STATIC_LOGGING_CATEGORY(lcOdbc, "qt.sql.odbc") using namespace Qt::StringLiterals; diff --git a/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp b/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp index c574772fd77..05af02e1565 100644 --- a/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp +++ b/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp @@ -39,7 +39,7 @@ Q_DECLARE_METATYPE(sqlite3_stmt*) QT_BEGIN_NAMESPACE -static Q_LOGGING_CATEGORY(lcSqlite, "qt.sql.sqlite") +Q_STATIC_LOGGING_CATEGORY(lcSqlite, "qt.sql.sqlite") using namespace Qt::StringLiterals; diff --git a/src/sql/kernel/qsqldatabase.cpp b/src/sql/kernel/qsqldatabase.cpp index c25fabf0a4b..e44533291a3 100644 --- a/src/sql/kernel/qsqldatabase.cpp +++ b/src/sql/kernel/qsqldatabase.cpp @@ -18,7 +18,7 @@ QT_BEGIN_NAMESPACE -static Q_LOGGING_CATEGORY(lcSqlDb, "qt.sql.qsqldatabase") +Q_STATIC_LOGGING_CATEGORY(lcSqlDb, "qt.sql.qsqldatabase") using namespace Qt::StringLiterals; diff --git a/src/sql/kernel/qsqlquery.cpp b/src/sql/kernel/qsqlquery.cpp index 1ada7f9e27a..63f782fe222 100644 --- a/src/sql/kernel/qsqlquery.cpp +++ b/src/sql/kernel/qsqlquery.cpp @@ -20,7 +20,7 @@ QT_BEGIN_NAMESPACE -static Q_LOGGING_CATEGORY(lcSqlQuery, "qt.sql.qsqlquery") +Q_STATIC_LOGGING_CATEGORY(lcSqlQuery, "qt.sql.qsqlquery") class QSqlQueryPrivate { |