|
17 | 17 | #include <qnamespace.h> |
18 | 18 | #include <qobject.h> |
19 | 19 | #include <qobjectdefs.h> |
| 20 | +#include <qpair.h> |
20 | 21 | #include <qstring.h> |
21 | 22 | #include <qstringview.h> |
22 | 23 | #include <qsysinfo.h> |
@@ -200,16 +201,15 @@ void LogManager::filterCategory(QLoggingCategory* category) { |
200 | 201 |
|
201 | 202 | if (isQs && !instance->sparse) { |
202 | 203 | // We assume the category name pointer will always be the same and be comparable in the message handler. |
203 | | - LogManager::instance()->sparseFilters.insert( |
204 | | - static_cast<const void*>(category->categoryName()), |
205 | | - filter |
206 | | - ); |
| 204 | + instance->sparseFilters.insert(static_cast<const void*>(category->categoryName()), filter); |
207 | 205 |
|
208 | 206 | // all enabled by default |
209 | 207 | CategoryFilter().apply(category); |
210 | 208 | } else { |
211 | 209 | filter.apply(category); |
212 | 210 | } |
| 211 | + |
| 212 | + instance->allFilters.insert(categoryName, filter); |
213 | 213 | } |
214 | 214 |
|
215 | 215 | LogManager* LogManager::instance() { |
@@ -269,6 +269,10 @@ QString LogManager::rulesString() const { return this->mRulesString; } |
269 | 269 | QtMsgType LogManager::defaultLevel() const { return this->mDefaultLevel; } |
270 | 270 | bool LogManager::isSparse() const { return this->sparse; } |
271 | 271 |
|
| 272 | +CategoryFilter LogManager::getFilter(QLatin1StringView category) { |
| 273 | + return this->allFilters.value(category); |
| 274 | +} |
| 275 | + |
272 | 276 | void LoggingThreadProxy::initInThread() { |
273 | 277 | this->logging = new ThreadLogging(this); |
274 | 278 | this->logging->init(); |
@@ -527,7 +531,7 @@ bool DeviceReader::readU64(quint64* data) { |
527 | 531 | void EncodedLogWriter::setDevice(QIODevice* target) { this->buffer.setDevice(target); } |
528 | 532 | void EncodedLogReader::setDevice(QIODevice* source) { this->reader.setDevice(source); } |
529 | 533 |
|
530 | | -constexpr quint8 LOG_VERSION = 1; |
| 534 | +constexpr quint8 LOG_VERSION = 2; |
531 | 535 |
|
532 | 536 | bool EncodedLogWriter::writeHeader() { |
533 | 537 | this->buffer.writeU8(LOG_VERSION); |
@@ -673,14 +677,18 @@ bool EncodedLogReader::read(LogMessage* slot) { |
673 | 677 | QByteArray body; |
674 | 678 | if (!this->readString(&body)) return false; |
675 | 679 |
|
676 | | - *slot = LogMessage(msgType, QLatin1StringView(category), body, this->lastMessageTime); |
| 680 | + *slot = LogMessage(msgType, QLatin1StringView(category.first), body, this->lastMessageTime); |
677 | 681 | slot->readCategoryId = categoryId; |
678 | 682 | } |
679 | 683 |
|
680 | 684 | this->recentMessages.emplace(*slot); |
681 | 685 | return true; |
682 | 686 | } |
683 | 687 |
|
| 688 | +CategoryFilter EncodedLogReader::categoryFilterById(quint16 id) { |
| 689 | + return this->categories.value(id).second; |
| 690 | +} |
| 691 | + |
684 | 692 | void EncodedLogWriter::writeOp(EncodedLogOpcode opcode) { this->buffer.writeU8(opcode); } |
685 | 693 |
|
686 | 694 | void EncodedLogWriter::writeVarInt(quint32 n) { |
@@ -742,14 +750,31 @@ quint16 EncodedLogWriter::getOrCreateCategory(QLatin1StringView category) { |
742 | 750 | auto id = this->nextCategory++; |
743 | 751 | this->categories.insert(category, id); |
744 | 752 |
|
| 753 | + auto filter = LogManager::instance()->getFilter(category); |
| 754 | + quint8 flags = 0; |
| 755 | + flags |= filter.debug << 0; |
| 756 | + flags |= filter.info << 1; |
| 757 | + flags |= filter.warn << 2; |
| 758 | + flags |= filter.critical << 3; |
| 759 | + |
| 760 | + this->buffer.writeU8(flags); |
745 | 761 | return id; |
746 | 762 | } |
747 | 763 | } |
748 | 764 |
|
749 | 765 | bool EncodedLogReader::registerCategory() { |
750 | 766 | QByteArray name; |
| 767 | + quint8 flags = 0; |
751 | 768 | if (!this->readString(&name)) return false; |
752 | | - this->categories.append(name); |
| 769 | + if (!this->reader.readU8(&flags)) return false; |
| 770 | + |
| 771 | + CategoryFilter filter; |
| 772 | + filter.debug = (flags >> 0) & 1; |
| 773 | + filter.info = (flags >> 1) & 1; |
| 774 | + filter.warn = (flags >> 2) & 1; |
| 775 | + filter.critical = (flags >> 3) & 1; |
| 776 | + |
| 777 | + this->categories.append(qMakePair(name, filter)); |
753 | 778 | return true; |
754 | 779 | } |
755 | 780 |
|
@@ -789,6 +814,8 @@ bool LogReader::continueReading() { |
789 | 814 | if (this->filters.contains(message.readCategoryId)) { |
790 | 815 | filter = this->filters.value(message.readCategoryId); |
791 | 816 | } else { |
| 817 | + filter = this->reader.categoryFilterById(message.readCategoryId); |
| 818 | + |
792 | 819 | for (const auto& rule: this->rules) { |
793 | 820 | filter.applyRule(message.category, rule); |
794 | 821 | } |
|
0 commit comments