summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2023-08-22 17:04:58 -0700
committerThiago Macieira <thiago.macieira@intel.com>2023-10-24 04:04:19 -0700
commit039ea9b40f1ab80ce72a688239d7c0825d55bb59 (patch)
tree983c1bc85df438aadf66f05374aea697ff442b99
parenta668ed44dc98a377a5253410d65fe4b3667e87e6 (diff)
QLogging: simplify qDefaultMessageHandler() with a global constant
Namely, a function pointer to the actual sink function. This doesn't remove the future ability to iterate over multiple sinks, but I removed the comment anyway because it doesn't look like we'll ever implement that. Change-Id: Ifa1111900d6945ea8e05fffd177de7fa46230259 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r--src/corelib/global/qlogging.cpp54
-rw-r--r--src/corelib/kernel/qcore_mac_p.h7
2 files changed, 35 insertions, 26 deletions
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp
index 3f0cb67989..bb8706bcac 100644
--- a/src/corelib/global/qlogging.cpp
+++ b/src/corelib/global/qlogging.cpp
@@ -1901,40 +1901,46 @@ static void stderr_message_handler(QtMsgType type, const QMessageLogContext &con
fflush(stderr);
}
+using SystemMessageSink = bool(QtMsgType, const QMessageLogContext &, const QString &);
+static constexpr SystemMessageSink *systemMessageSink =
+#if defined(QT_BOOTSTRAPPED)
+ nullptr
+#elif defined(Q_OS_WIN)
+ win_message_handler
+#elif QT_CONFIG(slog2)
+ slog2_default_handler
+#elif QT_CONFIG(journald)
+ systemd_default_message_handler
+#elif QT_CONFIG(syslog)
+ syslog_default_message_handler
+#elif defined(Q_OS_ANDROID)
+ android_default_message_handler
+#elif defined(QT_USE_APPLE_UNIFIED_LOGGING)
+ AppleUnifiedLogger::messageHandler
+#elif defined Q_OS_WASM
+ wasm_default_message_handler
+#else
+ nullptr
+#endif
+ ;
+
/*!
\internal
*/
static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &context,
const QString &message)
{
- bool handledStderr = false;
-
// A message sink logs the message to a structured or unstructured destination,
// optionally formatting the message if the latter, and returns true if the sink
// handled stderr output as well, which will shortcut our default stderr output.
- // In the future, if we allow multiple/dynamic sinks, this will be iterating
- // a list of sinks.
-
-#if !defined(QT_BOOTSTRAPPED)
-# if defined(Q_OS_WIN)
- handledStderr |= win_message_handler(type, context, message);
-# elif QT_CONFIG(slog2)
- handledStderr |= slog2_default_handler(type, context, message);
-# elif QT_CONFIG(journald)
- handledStderr |= systemd_default_message_handler(type, context, message);
-# elif QT_CONFIG(syslog)
- handledStderr |= syslog_default_message_handler(type, context, message);
-# elif defined(Q_OS_ANDROID)
- handledStderr |= android_default_message_handler(type, context, message);
-# elif defined(QT_USE_APPLE_UNIFIED_LOGGING)
- handledStderr |= AppleUnifiedLogger::messageHandler(type, context, message);
-# elif defined Q_OS_WASM
- handledStderr |= wasm_default_message_handler(type, context, message);
-# endif
-#endif
- if (!handledStderr)
- stderr_message_handler(type, context, message);
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_GCC("-Waddress") // "the address of ~~ will never be NULL
+ if (systemMessageSink && systemMessageSink(type, context, message))
+ return;
+QT_WARNING_POP
+
+ stderr_message_handler(type, context, message);
}
#if defined(Q_COMPILER_THREAD_LOCAL)
diff --git a/src/corelib/kernel/qcore_mac_p.h b/src/corelib/kernel/qcore_mac_p.h
index 1b0283e77b..495d0df13f 100644
--- a/src/corelib/kernel/qcore_mac_p.h
+++ b/src/corelib/kernel/qcore_mac_p.h
@@ -236,8 +236,11 @@ QT_BEGIN_NAMESPACE
class Q_CORE_EXPORT AppleUnifiedLogger
{
public:
- static bool messageHandler(QtMsgType msgType, const QMessageLogContext &context, const QString &message,
- const QString &subsystem = QString());
+ static bool messageHandler(QtMsgType msgType, const QMessageLogContext &context,
+ const QString &message)
+ { return messageHandler(msgType, context, message, QString()); }
+ static bool messageHandler(QtMsgType msgType, const QMessageLogContext &context,
+ const QString &message, const QString &subsystem);
static bool preventsStderrLogging();
private:
static os_log_type_t logTypeForMessageType(QtMsgType msgType);