diff options
Diffstat (limited to 'common/log.cpp')
-rw-r--r-- | common/log.cpp | 47 |
1 files changed, 30 insertions, 17 deletions
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 @@ | |||
1 | #include "log.h" | 1 | #include "log.h" |
2 | 2 | ||
3 | #include <QString> | 3 | #include <QString> |
4 | #include <QDir> | ||
4 | #include <QIODevice> | 5 | #include <QIODevice> |
5 | #include <QCoreApplication> | 6 | #include <QCoreApplication> |
6 | #include <QSettings> | 7 | #include <QSettings> |
@@ -282,14 +283,16 @@ static bool containsItemStartingWith(const QByteArray &pattern, const QByteArray | |||
282 | for (const auto &item : list) { | 283 | for (const auto &item : list) { |
283 | if (item.startsWith('*')) { | 284 | if (item.startsWith('*')) { |
284 | auto stripped = item.mid(1); | 285 | auto stripped = item.mid(1); |
285 | stripped.endsWith('*'); | 286 | if (stripped.endsWith('*')) { |
286 | stripped.chop(1); | 287 | stripped.chop(1); |
288 | } | ||
287 | if (pattern.contains(stripped)) { | 289 | if (pattern.contains(stripped)) { |
288 | return true; | 290 | return true; |
289 | } | 291 | } |
290 | } | 292 | } else { |
291 | if (pattern.startsWith(item)) { | 293 | if (pattern.contains(item)) { |
292 | return true; | 294 | return true; |
295 | } | ||
293 | } | 296 | } |
294 | } | 297 | } |
295 | return false; | 298 | return false; |
@@ -307,29 +310,39 @@ static bool caseInsensitiveContains(const QByteArray &pattern, const QByteArrayL | |||
307 | 310 | ||
308 | static QByteArray getFileName(const char *file) | 311 | static QByteArray getFileName(const char *file) |
309 | { | 312 | { |
310 | auto filename = QByteArray(file).split('/').last(); | 313 | static char sep = QDir::separator().toLatin1(); |
314 | auto filename = QByteArray(file).split(sep).last(); | ||
311 | return filename.split('.').first(); | 315 | return filename.split('.').first(); |
312 | } | 316 | } |
313 | 317 | ||
314 | QDebug Sink::Log::debugStream(DebugLevel debugLevel, int line, const char *file, const char *function, const char *debugArea, const char *debugComponent) | 318 | bool isFiltered(DebugLevel debugLevel, const QByteArray &fullDebugArea) |
315 | { | 319 | { |
316 | static NullStream nullstream; | ||
317 | if (debugLevel < debugOutputLevel()) { | 320 | if (debugLevel < debugOutputLevel()) { |
318 | return QDebug(&nullstream); | 321 | return true; |
319 | } | 322 | } |
323 | auto areas = debugOutputFilter(Sink::Log::Area); | ||
324 | if (debugLevel <= Sink::Log::Trace && !areas.isEmpty()) { | ||
325 | if (!containsItemStartingWith(fullDebugArea, areas)) { | ||
326 | return true; | ||
327 | } | ||
328 | } | ||
329 | return false; | ||
330 | } | ||
320 | 331 | ||
332 | QDebug Sink::Log::debugStream(DebugLevel debugLevel, int line, const char *file, const char *function, const char *debugArea, const char *debugComponent) | ||
333 | { | ||
321 | if (sPrimaryComponent.isEmpty()) { | 334 | if (sPrimaryComponent.isEmpty()) { |
322 | sPrimaryComponent = getProgramName(); | 335 | sPrimaryComponent = getProgramName(); |
323 | } | 336 | } |
324 | QString fullDebugArea = sPrimaryComponent + "." + (debugComponent ? (QString::fromLatin1(debugComponent) + ".") : "") + (debugArea ? QString::fromLatin1(debugArea) : getFileName(file)); | 337 | const QByteArray fullDebugArea = sPrimaryComponent + "." + |
338 | (debugComponent ? (QByteArray{debugComponent} + ".") : "") + | ||
339 | (debugArea ? QByteArray{debugArea} : getFileName(file)); | ||
325 | 340 | ||
326 | collectDebugArea(fullDebugArea); | 341 | collectDebugArea(fullDebugArea); |
327 | 342 | ||
328 | auto areas = debugOutputFilter(Sink::Log::Area); | 343 | static NullStream nullstream; |
329 | if (debugLevel <= Sink::Log::Trace && !areas.isEmpty()) { | 344 | if (isFiltered(debugLevel, fullDebugArea)) { |
330 | if (!containsItemStartingWith(fullDebugArea.toUtf8(), areas)) { | 345 | return QDebug(&nullstream); |
331 | return QDebug(&nullstream); | ||
332 | } | ||
333 | } | 346 | } |
334 | 347 | ||
335 | QString prefix; | 348 | QString prefix; |
@@ -378,12 +391,12 @@ QDebug Sink::Log::debugStream(DebugLevel debugLevel, int line, const char *file, | |||
378 | } | 391 | } |
379 | static std::atomic<int> maxDebugAreaSize{25}; | 392 | static std::atomic<int> maxDebugAreaSize{25}; |
380 | maxDebugAreaSize = qMax(fullDebugArea.size(), maxDebugAreaSize.load()); | 393 | maxDebugAreaSize = qMax(fullDebugArea.size(), maxDebugAreaSize.load()); |
381 | output += QString(" %1 ").arg(fullDebugArea.leftJustified(maxDebugAreaSize, ' ', false)); | 394 | output += QString(" %1 ").arg(QString{fullDebugArea}.leftJustified(maxDebugAreaSize, ' ', false)); |
382 | if (useColor) { | 395 | if (useColor) { |
383 | output += resetColor; | 396 | output += resetColor; |
384 | } | 397 | } |
385 | if (showFunction) { | 398 | if (showFunction) { |
386 | output += QString(" %3").arg(fullDebugArea.leftJustified(25, ' ', true)); | 399 | output += QString(" %3").arg(QString{fullDebugArea}.leftJustified(25, ' ', true)); |
387 | } | 400 | } |
388 | if (showLocation) { | 401 | if (showLocation) { |
389 | const auto filename = QString::fromLatin1(file).split('/').last(); | 402 | const auto filename = QString::fromLatin1(file).split('/').last(); |