diff options
Diffstat (limited to 'common/log.cpp')
-rw-r--r-- | common/log.cpp | 69 |
1 files changed, 59 insertions, 10 deletions
diff --git a/common/log.cpp b/common/log.cpp index 821df06..a3df04c 100644 --- a/common/log.cpp +++ b/common/log.cpp | |||
@@ -6,8 +6,11 @@ | |||
6 | #include <QSettings> | 6 | #include <QSettings> |
7 | #include <QStandardPaths> | 7 | #include <QStandardPaths> |
8 | #include <QSharedPointer> | 8 | #include <QSharedPointer> |
9 | #include <QMutex> | ||
10 | #include <QMutexLocker> | ||
9 | #include <iostream> | 11 | #include <iostream> |
10 | #include <unistd.h> | 12 | #include <unistd.h> |
13 | #include <memory> | ||
11 | 14 | ||
12 | using namespace Sink::Log; | 15 | using namespace Sink::Log; |
13 | 16 | ||
@@ -218,9 +221,63 @@ static QByteArray getProgramName() | |||
218 | } | 221 | } |
219 | } | 222 | } |
220 | 223 | ||
224 | static QSharedPointer<QSettings> debugAreasConfig() | ||
225 | { | ||
226 | return QSharedPointer<QSettings>::create(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/sink/debugAreas.ini", QSettings::IniFormat); | ||
227 | } | ||
228 | |||
229 | class DebugAreaCollector { | ||
230 | public: | ||
231 | DebugAreaCollector() | ||
232 | { | ||
233 | QMutexLocker locker(&mutex); | ||
234 | mDebugAreas = debugAreasConfig()->value("areas").value<QString>().split(';').toSet(); | ||
235 | } | ||
236 | |||
237 | ~DebugAreaCollector() | ||
238 | { | ||
239 | QMutexLocker locker(&mutex); | ||
240 | mDebugAreas += debugAreasConfig()->value("areas").value<QString>().split(';').toSet(); | ||
241 | debugAreasConfig()->setValue("areas", QVariant::fromValue(mDebugAreas.toList().join(';'))); | ||
242 | } | ||
243 | |||
244 | void add(const QString &area) | ||
245 | { | ||
246 | QMutexLocker locker(&mutex); | ||
247 | mDebugAreas << area; | ||
248 | } | ||
249 | |||
250 | QSet<QString> debugAreas() | ||
251 | { | ||
252 | QMutexLocker locker(&mutex); | ||
253 | return mDebugAreas; | ||
254 | } | ||
255 | |||
256 | QMutex mutex; | ||
257 | QSet<QString> mDebugAreas; | ||
258 | }; | ||
259 | |||
260 | static auto sDebugAreaCollector = std::unique_ptr<DebugAreaCollector>(new DebugAreaCollector); | ||
261 | |||
262 | QSet<QString> Sink::Log::debugAreas() | ||
263 | { | ||
264 | return sDebugAreaCollector->debugAreas(); | ||
265 | } | ||
266 | |||
267 | static void collectDebugArea(const QString &debugArea) | ||
268 | { | ||
269 | sDebugAreaCollector->add(debugArea); | ||
270 | } | ||
271 | |||
221 | static bool containsItemStartingWith(const QByteArray &pattern, const QByteArrayList &list) | 272 | static bool containsItemStartingWith(const QByteArray &pattern, const QByteArrayList &list) |
222 | { | 273 | { |
223 | for (const auto &item : list) { | 274 | for (const auto &item : list) { |
275 | if (item.startsWith('*')) { | ||
276 | auto stripped = item.mid(1); | ||
277 | if (pattern.contains(stripped)) { | ||
278 | return true; | ||
279 | } | ||
280 | } | ||
224 | if (pattern.startsWith(item)) { | 281 | if (pattern.startsWith(item)) { |
225 | return true; | 282 | return true; |
226 | } | 283 | } |
@@ -248,9 +305,9 @@ QDebug Sink::Log::debugStream(DebugLevel debugLevel, int line, const char *file, | |||
248 | if (sPrimaryComponent.isEmpty()) { | 305 | if (sPrimaryComponent.isEmpty()) { |
249 | sPrimaryComponent = getProgramName(); | 306 | sPrimaryComponent = getProgramName(); |
250 | } | 307 | } |
251 | QString fullDebugArea = sPrimaryComponent + "."+ QString::fromLatin1(debugComponent) + "." + QString::fromLatin1(debugArea); | 308 | QString fullDebugArea = sPrimaryComponent + "." + (debugComponent ? (QString::fromLatin1(debugComponent) + ".") : "") + (debugArea ? QString::fromLatin1(debugArea) : ""); |
252 | 309 | ||
253 | //TODO add to autocompletion | 310 | collectDebugArea(fullDebugArea); |
254 | 311 | ||
255 | auto areas = debugOutputFilter(Sink::Log::Area); | 312 | auto areas = debugOutputFilter(Sink::Log::Area); |
256 | if (!areas.isEmpty()) { | 313 | if (!areas.isEmpty()) { |
@@ -258,14 +315,6 @@ QDebug Sink::Log::debugStream(DebugLevel debugLevel, int line, const char *file, | |||
258 | return QDebug(&nullstream); | 315 | return QDebug(&nullstream); |
259 | } | 316 | } |
260 | } | 317 | } |
261 | // static QByteArray programName = getProgramName(); | ||
262 | // | ||
263 | // auto filter = debugOutputFilter(Sink::Log::ApplicationName); | ||
264 | // if (!filter.isEmpty() && !filter.contains(programName)) { | ||
265 | // if (!containsItemStartingWith(programName, filter)) { | ||
266 | // return QDebug(&nullstream); | ||
267 | // } | ||
268 | // } | ||
269 | 318 | ||
270 | QString prefix; | 319 | QString prefix; |
271 | int prefixColorCode = ANSI_Colors::DoNothing; | 320 | int prefixColorCode = ANSI_Colors::DoNothing; |