refs #446, changed log handler as discussed in slack

This commit is contained in:
Klaus Basan
2015-06-19 23:15:23 +02:00
committed by Mathew Sutcliffe
parent 9b77e1fc5c
commit 9d0408138a
3 changed files with 16 additions and 8 deletions

View File

@@ -21,7 +21,7 @@
#include "statusmessagelist.h"
#include "pixmap.h"
#include "iconlist.h"
#include "identifier.h"
#include "identifierlist.h"
#include "eventallclasses.h"
#include <QtNetwork/QHostInfo>
#include <QProcessEnvironment>
@@ -33,6 +33,7 @@
*/
void BlackMisc::Math::registerMetadata()
{
// void
}
/*
@@ -107,6 +108,7 @@ void BlackMisc::registerMetadata()
CLogCategoryList::registerMetadata();
CPixmap::registerMetadata();
CIdentifier::registerMetadata();
CIdentifierList::registerMetadata();
// sub namespaces
PhysicalQuantities::registerMetadata();

View File

@@ -29,8 +29,10 @@ namespace BlackMisc
QMetaObject::invokeMethod(CLogHandler::instance(), "logLocalMessage", Q_ARG(BlackMisc::CStatusMessage, statusMessage));
}
void CLogHandler::install()
void CLogHandler::install(bool skipIfAlreadyInstalled)
{
if (skipIfAlreadyInstalled && m_oldHandler) { return; }
Q_ASSERT_X(!m_oldHandler, Q_FUNC_INFO, "Re-installing the log handler should be avoided");
m_oldHandler = qInstallMessageHandler(messageHandler);
}
@@ -107,6 +109,13 @@ namespace BlackMisc
emit remoteMessageLogged(statusMessage);
}
void BlackMisc::CLogHandler::enableConsoleOutput(bool enable)
{
Q_ASSERT_X(m_oldHandler, Q_FUNC_INFO, "Install the log handler before using it");
Q_ASSERT_X(thread() == QThread::currentThread(), Q_FUNC_INFO, "Wrong thread");
m_enableFallThrough = enable;
}
void CLogHandler::logMessage(const CStatusMessage &statusMessage)
{
collectGarbage();
@@ -115,6 +124,7 @@ namespace BlackMisc
if (isFallThroughEnabled(handlers))
{
Q_ASSERT_X(m_oldHandler, Q_FUNC_INFO, "Handler must be installed");
QtMsgType type;
QString category;
QString message;

View File

@@ -42,7 +42,7 @@ namespace BlackMisc
static CLogHandler *instance();
//! Tell the CLogHandler to install itself with qInstallMessageHandler.
void install();
void install(bool skipIfAlreadyInstalled = false);
//! Return a pattern handler for subscribing to all messages which match the given pattern.
//! \warning This must only be called from the main thread.
@@ -74,11 +74,7 @@ namespace BlackMisc
void logRemoteMessage(const BlackMisc::CStatusMessage &message);
//! Enable or disable the default Qt handler.
void enableConsoleOutput(bool enable)
{
Q_ASSERT(thread() == QThread::currentThread());
m_enableFallThrough = enable;
}
void enableConsoleOutput(bool enable);
private:
void logMessage(const BlackMisc::CStatusMessage &message);