LeechCraft 0.6.70-17609-g3dde4097dd
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
loggingfilter.cpp
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#include "loggingfilter.h"
10#include <QLoggingCategory>
11
12namespace LC::Util
13{
15 {
17 QHash<QLoggingCategory*, QList<QtMsgType>> Disabled_ {};
18 QLoggingCategory::CategoryFilter PreviousFilter_ {};
19 };
20
21 QList<LoggingFilter::Context> LoggingFilter::ContextStack_;
22
24 {
25 ContextStack_.push_back ({ .ToDisable_ = cats });
26 ContextStack_.back ().PreviousFilter_ = QLoggingCategory::installFilter (&Filter);
27 }
28
30 {
31 const auto& context = ContextStack_.takeLast ();
32 for (const auto& [cat, levels] : context.Disabled_.asKeyValueRange ())
33 for (const auto level : levels)
34 cat->setEnabled (level, true);
35
36 QLoggingCategory::installFilter (context.PreviousFilter_);
37 }
38
39 void LoggingFilter::Filter (QLoggingCategory *category)
40 {
41 auto& context = ContextStack_.back ();
42
43 if (context.PreviousFilter_)
44 context.PreviousFilter_ (category);
45
46 for (const auto level : context.ToDisable_.value (QLatin1String { category->categoryName () }))
47 if (category->isEnabled (level))
48 {
49 category->setEnabled (level, false);
50 context.Disabled_ [category] << level;
51 }
52 }
53}
QHash< QLatin1String, QList< QtMsgType > > Categories
LoggingFilter(const Categories &cats)
QLoggingCategory::CategoryFilter PreviousFilter_
QHash< QLoggingCategory *, QList< QtMsgType > > Disabled_