mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-09 13:35:34 +08:00
refs #338 CLogHandler: cleaned up the logic for selectively enabling console output, with the help of the partial ordering feature of CLogPattern::isProperSubsetOf.
This commit is contained in:
@@ -54,7 +54,7 @@ namespace BlackMisc
|
|||||||
auto it = std::find_if(m_patternHandlers.begin(), m_patternHandlers.end(), finder);
|
auto it = std::find_if(m_patternHandlers.begin(), m_patternHandlers.end(), finder);
|
||||||
if (it == m_patternHandlers.end())
|
if (it == m_patternHandlers.end())
|
||||||
{
|
{
|
||||||
auto *handler = new CLogPatternHandler(this, m_enableFallThrough);
|
auto *handler = new CLogPatternHandler(this);
|
||||||
topologicallySortedInsert(m_patternHandlers, PatternPair(pattern, handler), comparator);
|
topologicallySortedInsert(m_patternHandlers, PatternPair(pattern, handler), comparator);
|
||||||
return handler;
|
return handler;
|
||||||
}
|
}
|
||||||
@@ -77,22 +77,11 @@ namespace BlackMisc
|
|||||||
return m_handlers;
|
return m_handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLogHandler::enableConsoleOutput(bool enable)
|
|
||||||
{
|
|
||||||
Q_ASSERT(thread() == QThread::currentThread());
|
|
||||||
|
|
||||||
m_enableFallThrough = enable;
|
|
||||||
for (const auto &pair : m_patternHandlers)
|
|
||||||
{
|
|
||||||
pair.second->enableConsoleOutput(enable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CLogHandler::isFallThroughEnabled(const QList<CLogPatternHandler *> &handlers) const
|
bool CLogHandler::isFallThroughEnabled(const QList<CLogPatternHandler *> &handlers) const
|
||||||
{
|
{
|
||||||
for (const auto *handler : handlers)
|
for (const auto *handler : handlers)
|
||||||
{
|
{
|
||||||
if (handler->m_enableFallThrough != m_enableFallThrough)
|
if (! handler->m_inheritFallThrough)
|
||||||
{
|
{
|
||||||
return handler->m_enableFallThrough;
|
return handler->m_enableFallThrough;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,11 @@ namespace BlackMisc
|
|||||||
void logRemoteMessage(const BlackMisc::CStatusMessage &message);
|
void logRemoteMessage(const BlackMisc::CStatusMessage &message);
|
||||||
|
|
||||||
//! Enable or disable the default Qt handler.
|
//! Enable or disable the default Qt handler.
|
||||||
void enableConsoleOutput(bool enable);
|
void enableConsoleOutput(bool enable)
|
||||||
|
{
|
||||||
|
Q_ASSERT(thread() == QThread::currentThread());
|
||||||
|
m_enableFallThrough = enable;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void logMessage(const BlackMisc::CStatusMessage &message);
|
void logMessage(const BlackMisc::CStatusMessage &message);
|
||||||
@@ -90,7 +94,25 @@ namespace BlackMisc
|
|||||||
* CLogPatternHandler or the base CLogHandler, if this handler's pattern is a subset of the
|
* CLogPatternHandler or the base CLogHandler, if this handler's pattern is a subset of the
|
||||||
* other handler's pattern. Which is to say, more specific patterns can override less specific patterns.
|
* other handler's pattern. Which is to say, more specific patterns can override less specific patterns.
|
||||||
*/
|
*/
|
||||||
void enableConsoleOutput(bool enable) { Q_ASSERT(thread() == QThread::currentThread()); m_enableFallThrough = enable; }
|
void enableConsoleOutput(bool enable)
|
||||||
|
{
|
||||||
|
Q_ASSERT(thread() == QThread::currentThread());
|
||||||
|
m_inheritFallThrough = false;
|
||||||
|
m_enableFallThrough = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* The policy of whether to enable or disable the default Qt handler for messages which match
|
||||||
|
* the relevant pattern will be inherited from the base CLogHandler, or from another CLogPatternHandler
|
||||||
|
* which matches a superset of the messages which this one matches.
|
||||||
|
*
|
||||||
|
* This is the default, but can be used to reverse the effect of calling enableConsoleOutput.
|
||||||
|
*/
|
||||||
|
void inheritConsoleOutput()
|
||||||
|
{
|
||||||
|
Q_ASSERT(thread() == QThread::currentThread());
|
||||||
|
m_inheritFallThrough = true;
|
||||||
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/*!
|
/*!
|
||||||
@@ -108,8 +130,9 @@ namespace BlackMisc
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
friend class CLogHandler;
|
friend class CLogHandler;
|
||||||
CLogPatternHandler(QObject *parent, bool enableFallThrough) : QObject(parent), m_enableFallThrough(enableFallThrough) {}
|
CLogPatternHandler(QObject *parent) : QObject(parent) {}
|
||||||
bool m_enableFallThrough;
|
bool m_inheritFallThrough = true;
|
||||||
|
bool m_enableFallThrough = true;
|
||||||
|
|
||||||
bool canBeDeleted()
|
bool canBeDeleted()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user