Logging: Simplify message handler logic for windows
Incorporate the functionality of qWinMessageHandler in qDefaultMessageHandler. Change-Id: Iec5b19e187c0d2e3d8d0874280ba57f6fb21d7b4 Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
parent
fa3cc59868
commit
e6558184eb
@ -633,12 +633,21 @@ static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &con
|
|||||||
const QString &buf)
|
const QString &buf)
|
||||||
{
|
{
|
||||||
QString logMessage = qMessageFormatString(type, context, buf);
|
QString logMessage = qMessageFormatString(type, context, buf);
|
||||||
#if defined(Q_OS_WINCE)
|
|
||||||
|
#if defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB)
|
||||||
|
#if !defined(Q_OS_WINCE)
|
||||||
|
if (usingWinMain)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
// OutputDebugString is not threadsafe.
|
||||||
|
static QBasicMutex outputDebugStringMutex;
|
||||||
|
QMutexLocker locker(&outputDebugStringMutex);
|
||||||
OutputDebugString(reinterpret_cast<const wchar_t *>(logMessage.utf16()));
|
OutputDebugString(reinterpret_cast<const wchar_t *>(logMessage.utf16()));
|
||||||
#else
|
return;
|
||||||
|
}
|
||||||
|
#endif // Q_OS_WIN
|
||||||
fprintf(stderr, "%s", logMessage.toLocal8Bit().constData());
|
fprintf(stderr, "%s", logMessage.toLocal8Bit().constData());
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -728,18 +737,6 @@ void qErrnoWarning(int code, const char *msg, ...)
|
|||||||
qt_message_output(QtCriticalMsg, context, buf);
|
qt_message_output(QtCriticalMsg, context, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB)
|
|
||||||
extern Q_CORE_EXPORT void qWinMsgHandler(QtMsgType t, const char *str);
|
|
||||||
extern Q_CORE_EXPORT void qWinMessageHandler(QtMsgType t, const QMessageLogContext &context,
|
|
||||||
const QString &str);
|
|
||||||
|
|
||||||
void qWinMessageHandler2(QtMsgType t, const QMessageLogContext &context,
|
|
||||||
const char *str)
|
|
||||||
{
|
|
||||||
qWinMessageHandler(t, context, QString::fromLocal8Bit(str));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\typedef QtMsgHandler
|
\typedef QtMsgHandler
|
||||||
\relates <QtGlobal>
|
\relates <QtGlobal>
|
||||||
@ -852,10 +849,6 @@ QtMessageHandler qInstallMessageHandler(QtMessageHandler h)
|
|||||||
messageHandler = qDefaultMessageHandler;
|
messageHandler = qDefaultMessageHandler;
|
||||||
QtMessageHandler old = messageHandler;
|
QtMessageHandler old = messageHandler;
|
||||||
messageHandler = h;
|
messageHandler = h;
|
||||||
#if defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB)
|
|
||||||
if (!messageHandler && usingWinMain)
|
|
||||||
messageHandler = qWinMessageHandler;
|
|
||||||
#endif
|
|
||||||
return old;
|
return old;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -867,10 +860,6 @@ QtMsgHandler qInstallMsgHandler(QtMsgHandler h)
|
|||||||
msgHandler = qDefaultMsgHandler;
|
msgHandler = qDefaultMsgHandler;
|
||||||
QtMsgHandler old = msgHandler;
|
QtMsgHandler old = msgHandler;
|
||||||
msgHandler = h;
|
msgHandler = h;
|
||||||
#if defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB)
|
|
||||||
if (!msgHandler && usingWinMain)
|
|
||||||
msgHandler = qWinMsgHandler;
|
|
||||||
#endif
|
|
||||||
return old;
|
return old;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,46 +125,6 @@ QString QCoreApplicationPrivate::appName() const
|
|||||||
return QFileInfo(qAppFileName()).baseName();
|
return QFileInfo(qAppFileName()).baseName();
|
||||||
}
|
}
|
||||||
|
|
||||||
class QWinMsgHandlerCriticalSection
|
|
||||||
{
|
|
||||||
CRITICAL_SECTION cs;
|
|
||||||
public:
|
|
||||||
QWinMsgHandlerCriticalSection()
|
|
||||||
{ InitializeCriticalSection(&cs); }
|
|
||||||
~QWinMsgHandlerCriticalSection()
|
|
||||||
{ DeleteCriticalSection(&cs); }
|
|
||||||
|
|
||||||
void lock()
|
|
||||||
{ EnterCriticalSection(&cs); }
|
|
||||||
void unlock()
|
|
||||||
{ LeaveCriticalSection(&cs); }
|
|
||||||
};
|
|
||||||
|
|
||||||
// defined in qlogging.cpp
|
|
||||||
extern Q_CORE_EXPORT QString qMessageFormatString(QtMsgType type,
|
|
||||||
const QMessageLogContext &context,
|
|
||||||
const QString &str);
|
|
||||||
|
|
||||||
Q_CORE_EXPORT void qWinMessageHandler(QtMsgType t, const QMessageLogContext &context, const QString &str)
|
|
||||||
{
|
|
||||||
// cannot use QMutex here, because qWarning()s in the QMutex
|
|
||||||
// implementation may cause this function to recurse
|
|
||||||
static QWinMsgHandlerCriticalSection staticCriticalSection;
|
|
||||||
|
|
||||||
QString message = qMessageFormatString(t, context, str);
|
|
||||||
|
|
||||||
// OutputDebugString is not threadsafe.
|
|
||||||
staticCriticalSection.lock();
|
|
||||||
OutputDebugString((wchar_t*)message.utf16());
|
|
||||||
staticCriticalSection.unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_CORE_EXPORT void qWinMsgHandler(QtMsgType t, const char *str)
|
|
||||||
{
|
|
||||||
QMessageLogContext emptyContext;
|
|
||||||
qWinMessageHandler(t, emptyContext, QString::fromLocal8Bit(str));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
qWinMain() - Initializes Windows. Called from WinMain() in qtmain_win.cpp
|
qWinMain() - Initializes Windows. Called from WinMain() in qtmain_win.cpp
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
@ -187,9 +147,6 @@ void qWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdParam,
|
|||||||
already_called = true;
|
already_called = true;
|
||||||
usingWinMain = true;
|
usingWinMain = true;
|
||||||
|
|
||||||
// Install default debug handler
|
|
||||||
qInstallMessageHandler(qWinMessageHandler);
|
|
||||||
|
|
||||||
// Create command line
|
// Create command line
|
||||||
argv = qWinCmdLine<char>(cmdParam, int(strlen(cmdParam)), argc);
|
argv = qWinCmdLine<char>(cmdParam, int(strlen(cmdParam)), argc);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user