diff --git a/Telegram/SourceFiles/core/launcher.cpp b/Telegram/SourceFiles/core/launcher.cpp index 85079a923..3748be153 100644 --- a/Telegram/SourceFiles/core/launcher.cpp +++ b/Telegram/SourceFiles/core/launcher.cpp @@ -420,7 +420,6 @@ void Launcher::prepareSettings() { void Launcher::initQtMessageLogging() { static QtMessageHandler OriginalMessageHandler = nullptr; - static bool WritingQtMessage = false; OriginalMessageHandler = qInstallMessageHandler([]( QtMsgType type, const QMessageLogContext &context, @@ -429,10 +428,9 @@ void Launcher::initQtMessageLogging() { OriginalMessageHandler(type, context, msg); } if (Logs::DebugEnabled() || !Logs::started()) { - if (!WritingQtMessage) { - WritingQtMessage = true; + if (!Logs::WritingEntry()) { + // Sometimes Qt logs something inside our own logging. LOG((msg)); - WritingQtMessage = false; } } }); diff --git a/Telegram/SourceFiles/logs.cpp b/Telegram/SourceFiles/logs.cpp index 7ad8bbbda..d8c7adf3c 100644 --- a/Telegram/SourceFiles/logs.cpp +++ b/Telegram/SourceFiles/logs.cpp @@ -14,6 +14,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace { std::atomic ThreadCounter/* = 0*/; +thread_local bool WritingEntryFlag/* = false*/; + +class WritingEntryScope final { +public: + WritingEntryScope() { + WritingEntryFlag = true; + } + ~WritingEntryScope() { + WritingEntryFlag = false; + } +}; } // namespace @@ -73,6 +84,8 @@ public: void closeMain() { QMutexLocker lock(_logsMutex(LogDataMain)); + WritingEntryScope scope; + const auto file = files[LogDataMain].get(); if (file && file->isOpen()) { file->close(); @@ -98,6 +111,8 @@ public: void write(LogDataType type, const QString &msg) { QMutexLocker lock(_logsMutex(type)); + WritingEntryScope scope; + if (type != LogDataMain) { reopenDebug(); } @@ -323,6 +338,10 @@ bool DebugEnabled() { #endif } +bool WritingEntry() { + return WritingEntryFlag; +} + void start(not_null launcher) { Assert(LogsData == nullptr); diff --git a/Telegram/SourceFiles/logs.h b/Telegram/SourceFiles/logs.h index e42bf8b22..f45b07658 100644 --- a/Telegram/SourceFiles/logs.h +++ b/Telegram/SourceFiles/logs.h @@ -19,6 +19,7 @@ namespace Logs { void SetDebugEnabled(bool enabled); bool DebugEnabled(); +[[nodiscard]] bool WritingEntry(); void start(not_null launcher); bool started();