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>
This commit is contained in:
parent
a668ed44dc
commit
039ea9b40f
@ -1901,40 +1901,46 @@ static void stderr_message_handler(QtMsgType type, const QMessageLogContext &con
|
|||||||
fflush(stderr);
|
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
|
\internal
|
||||||
*/
|
*/
|
||||||
static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &context,
|
static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &context,
|
||||||
const QString &message)
|
const QString &message)
|
||||||
{
|
{
|
||||||
bool handledStderr = false;
|
|
||||||
|
|
||||||
// A message sink logs the message to a structured or unstructured destination,
|
// 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
|
// 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.
|
// 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)
|
QT_WARNING_PUSH
|
||||||
# if defined(Q_OS_WIN)
|
QT_WARNING_DISABLE_GCC("-Waddress") // "the address of ~~ will never be NULL
|
||||||
handledStderr |= win_message_handler(type, context, message);
|
if (systemMessageSink && systemMessageSink(type, context, message))
|
||||||
# elif QT_CONFIG(slog2)
|
return;
|
||||||
handledStderr |= slog2_default_handler(type, context, message);
|
QT_WARNING_POP
|
||||||
# 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);
|
||||||
stderr_message_handler(type, context, message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(Q_COMPILER_THREAD_LOCAL)
|
#if defined(Q_COMPILER_THREAD_LOCAL)
|
||||||
|
@ -236,8 +236,11 @@ QT_BEGIN_NAMESPACE
|
|||||||
class Q_CORE_EXPORT AppleUnifiedLogger
|
class Q_CORE_EXPORT AppleUnifiedLogger
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static bool messageHandler(QtMsgType msgType, const QMessageLogContext &context, const QString &message,
|
static bool messageHandler(QtMsgType msgType, const QMessageLogContext &context,
|
||||||
const QString &subsystem = QString());
|
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();
|
static bool preventsStderrLogging();
|
||||||
private:
|
private:
|
||||||
static os_log_type_t logTypeForMessageType(QtMsgType msgType);
|
static os_log_type_t logTypeForMessageType(QtMsgType msgType);
|
||||||
|
Loading…
Reference in New Issue
Block a user