From 8e91505e656743bd69166b3ba1cf29dfa7cfbea5 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 12 May 2017 10:33:52 +0200 Subject: Allow substring matches on the trace identifier --- common/log.cpp | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) (limited to 'common/log.cpp') diff --git a/common/log.cpp b/common/log.cpp index e9e16c6..d1a3a37 100644 --- a/common/log.cpp +++ b/common/log.cpp @@ -1,6 +1,7 @@ #include "log.h" #include +#include #include #include #include @@ -282,14 +283,16 @@ static bool containsItemStartingWith(const QByteArray &pattern, const QByteArray for (const auto &item : list) { if (item.startsWith('*')) { auto stripped = item.mid(1); - stripped.endsWith('*'); - stripped.chop(1); + if (stripped.endsWith('*')) { + stripped.chop(1); + } if (pattern.contains(stripped)) { return true; } - } - if (pattern.startsWith(item)) { - return true; + } else { + if (pattern.contains(item)) { + return true; + } } } return false; @@ -307,29 +310,39 @@ static bool caseInsensitiveContains(const QByteArray &pattern, const QByteArrayL static QByteArray getFileName(const char *file) { - auto filename = QByteArray(file).split('/').last(); + static char sep = QDir::separator().toLatin1(); + auto filename = QByteArray(file).split(sep).last(); return filename.split('.').first(); } -QDebug Sink::Log::debugStream(DebugLevel debugLevel, int line, const char *file, const char *function, const char *debugArea, const char *debugComponent) +bool isFiltered(DebugLevel debugLevel, const QByteArray &fullDebugArea) { - static NullStream nullstream; if (debugLevel < debugOutputLevel()) { - return QDebug(&nullstream); + return true; } + auto areas = debugOutputFilter(Sink::Log::Area); + if (debugLevel <= Sink::Log::Trace && !areas.isEmpty()) { + if (!containsItemStartingWith(fullDebugArea, areas)) { + return true; + } + } + return false; +} +QDebug Sink::Log::debugStream(DebugLevel debugLevel, int line, const char *file, const char *function, const char *debugArea, const char *debugComponent) +{ if (sPrimaryComponent.isEmpty()) { sPrimaryComponent = getProgramName(); } - QString fullDebugArea = sPrimaryComponent + "." + (debugComponent ? (QString::fromLatin1(debugComponent) + ".") : "") + (debugArea ? QString::fromLatin1(debugArea) : getFileName(file)); + const QByteArray fullDebugArea = sPrimaryComponent + "." + + (debugComponent ? (QByteArray{debugComponent} + ".") : "") + + (debugArea ? QByteArray{debugArea} : getFileName(file)); collectDebugArea(fullDebugArea); - auto areas = debugOutputFilter(Sink::Log::Area); - if (debugLevel <= Sink::Log::Trace && !areas.isEmpty()) { - if (!containsItemStartingWith(fullDebugArea.toUtf8(), areas)) { - return QDebug(&nullstream); - } + static NullStream nullstream; + if (isFiltered(debugLevel, fullDebugArea)) { + return QDebug(&nullstream); } QString prefix; @@ -378,12 +391,12 @@ QDebug Sink::Log::debugStream(DebugLevel debugLevel, int line, const char *file, } static std::atomic maxDebugAreaSize{25}; maxDebugAreaSize = qMax(fullDebugArea.size(), maxDebugAreaSize.load()); - output += QString(" %1 ").arg(fullDebugArea.leftJustified(maxDebugAreaSize, ' ', false)); + output += QString(" %1 ").arg(QString{fullDebugArea}.leftJustified(maxDebugAreaSize, ' ', false)); if (useColor) { output += resetColor; } if (showFunction) { - output += QString(" %3").arg(fullDebugArea.leftJustified(25, ' ', true)); + output += QString(" %3").arg(QString{fullDebugArea}.leftJustified(25, ' ', true)); } if (showLocation) { const auto filename = QString::fromLatin1(file).split('/').last(); -- cgit v1.2.3