Use LOG/DEBUG_LOG from lib_base.

This commit is contained in:
John Preston 2021-04-20 16:40:54 +04:00
parent 08e170a068
commit c360bb9da4
12 changed files with 65 additions and 87 deletions

View File

@ -21,17 +21,20 @@ void BaseIntegration::enterFromEventLoop(FnMut<void()> &&method) {
std::move(method));
}
bool BaseIntegration::logSkipDebug() {
return !Logs::DebugEnabled() && Logs::started();
}
void BaseIntegration::logMessageDebug(const QString &message) {
Logs::writeDebug(message);
}
void BaseIntegration::logMessage(const QString &message) {
#ifdef DEBUG_LOG
DEBUG_LOG((message));
#endif // DEBUG_LOG
Logs::writeMain(message);
}
void BaseIntegration::logAssertionViolation(const QString &info) {
#ifdef LOG
LOG(("Assertion Failed! ") + info);
#endif // LOG
Logs::writeMain("Assertion Failed! " + info);
CrashReports::SetAnnotation("Assertion", info);
}

View File

@ -11,11 +11,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Core {
class BaseIntegration : public base::Integration {
class BaseIntegration final : public base::Integration {
public:
BaseIntegration(int argc, char *argv[]);
void enterFromEventLoop(FnMut<void()> &&method) override;
bool logSkipDebug() override;
void logMessageDebug(const QString &message) override;
void logMessage(const QString &message) override;
void logAssertionViolation(const QString &info) override;

View File

@ -279,19 +279,7 @@ void Launcher::init() {
_arguments = readArguments(_argc, _argv);
prepareSettings();
static QtMessageHandler originalMessageHandler = nullptr;
originalMessageHandler = qInstallMessageHandler([](
QtMsgType type,
const QMessageLogContext &context,
const QString &msg) {
if (originalMessageHandler) {
originalMessageHandler(type, context, msg);
}
if (Logs::DebugEnabled() || !Logs::started()) {
LOG((msg));
}
});
initQtMessageLogging();
QApplication::setApplicationName(qsl("TelegramDesktop"));
@ -430,6 +418,26 @@ void Launcher::prepareSettings() {
processArguments();
}
void Launcher::initQtMessageLogging() {
static QtMessageHandler OriginalMessageHandler = nullptr;
static bool WritingQtMessage = false;
OriginalMessageHandler = qInstallMessageHandler([](
QtMsgType type,
const QMessageLogContext &context,
const QString &msg) {
if (OriginalMessageHandler) {
OriginalMessageHandler(type, context, msg);
}
if (Logs::DebugEnabled() || !Logs::started()) {
if (!WritingQtMessage) {
WritingQtMessage = true;
LOG((msg));
WritingQtMessage = false;
}
}
});
}
uint64 Launcher::installationTag() const {
return InstallationTag;
}

View File

@ -41,6 +41,7 @@ protected:
private:
void prepareSettings();
void initQtMessageLogging();
void processArguments();
QStringList readArguments(int argc, char *argv[]) const;

View File

@ -98,10 +98,6 @@ void UiIntegration::unregisterLeaveSubscription(not_null<QWidget*> widget) {
Core::App().unregisterLeaveSubscription(widget);
}
void UiIntegration::writeLogEntry(const QString &entry) {
Logs::writeMain(entry);
}
QString UiIntegration::emojiCacheFolder() {
return cWorkingDir() + "tdata/emoji";
}
@ -116,12 +112,6 @@ void UiIntegration::activationFromTopPanel() {
Platform::IgnoreApplicationActivationRightNow();
}
void UiIntegration::startFontsBegin() {
}
void UiIntegration::startFontsEnd() {
}
QString UiIntegration::timeFormat() {
return cTimeFormat();
}

View File

@ -30,20 +30,17 @@ struct MarkedTextContext {
HashtagMentionType type = HashtagMentionType::Telegram;
};
class UiIntegration : public Ui::Integration {
class UiIntegration final : public Ui::Integration {
public:
void postponeCall(FnMut<void()> &&callable) override;
void registerLeaveSubscription(not_null<QWidget*> widget) override;
void unregisterLeaveSubscription(not_null<QWidget*> widget) override;
void writeLogEntry(const QString &entry) override;
QString emojiCacheFolder() override;
void textActionsUpdated() override;
void activationFromTopPanel() override;
void startFontsBegin() override;
void startFontsEnd() override;
QString timeFormat() override;
std::shared_ptr<ClickHandler> createLinkHandler(

View File

@ -8,7 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "lang/lang_file_parser.h"
#include "base/parse_helper.h"
#include "ui/integration.h"
#include "base/debug_log.h"
#include <QtCore/QTextStream>
#include <QtCore/QFile>
@ -155,18 +155,19 @@ bool FileParser::readKeyValue(const char *&from, const char *end) {
QByteArray FileParser::ReadFile(const QString &absolutePath, const QString &relativePath) {
QFile file(QFileInfo::exists(relativePath) ? relativePath : absolutePath);
if (!file.open(QIODevice::ReadOnly)) {
Ui::Integration::Instance().writeLogEntry(u"Lang Error: Could not open file at '%1' ('%2')"_q.arg(relativePath, absolutePath));
LOG(("Lang Error: Could not open file at '%1' ('%2')")
.arg(relativePath, absolutePath));
return QByteArray();
}
if (file.size() > kLangFileLimit) {
Ui::Integration::Instance().writeLogEntry(u"Lang Error: File is too big: %1"_q.arg(file.size()));
LOG(("Lang Error: File is too big: %1").arg(file.size()));
return QByteArray();
}
constexpr auto kCodecMagicSize = 3;
auto codecMagic = file.read(kCodecMagicSize);
if (codecMagic.size() < kCodecMagicSize) {
Ui::Integration::Instance().writeLogEntry(u"Lang Error: Found bad file at '%1' ('%2')"_q.arg(relativePath, absolutePath));
LOG(("Lang Error: Found bad file at '%1' ('%2')").arg(relativePath, absolutePath));
return QByteArray();
}
file.seek(0);
@ -177,11 +178,11 @@ QByteArray FileParser::ReadFile(const QString &absolutePath, const QString &rela
stream.setCodec("UTF-16");
auto string = stream.readAll();
if (stream.status() != QTextStream::Ok) {
Ui::Integration::Instance().writeLogEntry(u"Lang Error: Could not read UTF-16 data from '%1' ('%2')"_q.arg(relativePath, absolutePath));
LOG(("Lang Error: Could not read UTF-16 data from '%1' ('%2')").arg(relativePath, absolutePath));
return QByteArray();
}
if (string.isEmpty()) {
Ui::Integration::Instance().writeLogEntry(u"Lang Error: Empty UTF-16 content in '%1' ('%2')"_q.arg(relativePath, absolutePath));
LOG(("Lang Error: Empty UTF-16 content in '%1' ('%2')").arg(relativePath, absolutePath));
return QByteArray();
}
return string.toUtf8();
@ -197,7 +198,7 @@ QByteArray FileParser::ReadFile(const QString &absolutePath, const QString &rela
data = data.mid(3); // skip UTF-8 BOM
}
if (data.isEmpty()) {
Ui::Integration::Instance().writeLogEntry(u"Lang Error: Empty UTF-8 content in '%1' ('%2')"_q.arg(relativePath, absolutePath));
LOG(("Lang Error: Empty UTF-8 content in '%1' ('%2')").arg(relativePath, absolutePath));
return QByteArray();
}
return data;

View File

@ -323,11 +323,6 @@ bool DebugEnabled() {
#endif
}
QString ProfilePrefix() {
const auto now = crl::profile();
return '[' + QString::number(now / 1000., 'f', 3) + "] ";
}
void start(not_null<Core::Launcher*> launcher) {
Assert(LogsData == nullptr);
@ -527,29 +522,21 @@ void writeMain(const QString &v) {
struct tm tm;
mylocaltime(&tm, &t);
QString msg(QString("[%1.%2.%3 %4:%5:%6] %7\n").arg(tm.tm_year + 1900).arg(tm.tm_mon + 1, 2, 10, QChar('0')).arg(tm.tm_mday, 2, 10, QChar('0')).arg(tm.tm_hour, 2, 10, QChar('0')).arg(tm.tm_min, 2, 10, QChar('0')).arg(tm.tm_sec, 2, 10, QChar('0')).arg(v));
const auto msg = QString("[%1.%2.%3 %4:%5:%6] %7\n"
).arg(tm.tm_year + 1900
).arg(tm.tm_mon + 1, 2, 10, QChar('0')
).arg(tm.tm_mday, 2, 10, QChar('0')
).arg(tm.tm_hour, 2, 10, QChar('0')
).arg(tm.tm_min, 2, 10, QChar('0')
).arg(tm.tm_sec, 2, 10, QChar('0')
).arg(v);
_logsWrite(LogDataMain, msg);
QString debugmsg(QString("%1 %2\n").arg(_logsEntryStart(), v));
_logsWrite(LogDataDebug, debugmsg);
writeDebug(v);
}
void writeDebug(const char *file, int32 line, const QString &v) {
const char *last = strstr(file, "/"), *found = 0;
while (last) {
found = last;
last = strstr(last + 1, "/");
}
last = strstr(file, "\\");
while (last) {
found = last;
last = strstr(last + 1, "\\");
}
if (found) {
file = found + 1;
}
QString msg(QString("%1 %2 (%3 : %4)\n").arg(_logsEntryStart(), v, file, QString::number(line)));
void writeDebug(const QString &v) {
const auto msg = QString("%1 %2\n").arg(_logsEntryStart(), v);
_logsWrite(LogDataDebug, msg);
#ifdef Q_OS_WIN
@ -562,12 +549,15 @@ void writeDebug(const char *file, int32 line, const QString &v) {
}
void writeTcp(const QString &v) {
QString msg(QString("%1 %2\n").arg(_logsEntryStart(), v));
const auto msg = QString("%1 %2\n").arg(_logsEntryStart(), v);
_logsWrite(LogDataTcp, msg);
}
void writeMtp(int32 dc, const QString &v) {
QString msg(QString("%1 (dc:%2) %3\n").arg(_logsEntryStart()).arg(dc).arg(v));
const auto msg = QString("%1 (dc:%2) %3\n").arg(
_logsEntryStart(),
QString::number(dc),
v);
_logsWrite(LogDataMtp, msg);
}

View File

@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/basic_types.h"
#include "base/assertion.h"
#include "base/debug_log.h"
namespace Core {
class Launcher;
@ -19,8 +20,6 @@ namespace Logs {
void SetDebugEnabled(bool enabled);
bool DebugEnabled();
QString ProfilePrefix();
void start(not_null<Core::Launcher*> launcher);
bool started();
void finish();
@ -31,8 +30,7 @@ void multipleInstances();
void closeMain();
void writeMain(const QString &v);
void writeDebug(const char *file, int32 line, const QString &v);
void writeDebug(const QString &v);
void writeTcp(const QString &v);
void writeMtp(int32 dc, const QString &v);
@ -70,18 +68,6 @@ inline MemoryBuffer mb(const void *ptr, uint32 size) {
} // namespace Logs
#define LOG(msg) (Logs::writeMain(QString msg))
//usage LOG(("log: %1 %2").arg(1).arg(2))
#define PROFILE_LOG(msg) (Logs::writeMain(Logs::ProfilePrefix() + QString msg))
#define DEBUG_LOG(msg) {\
if (Logs::DebugEnabled() || !Logs::started()) {\
Logs::writeDebug(SOURCE_FILE_BASENAME, __LINE__, QString msg);\
}\
}
//usage DEBUG_LOG(("log: %1 %2").arg(1).arg(2))
#define TCP_LOG(msg) {\
if (Logs::DebugEnabled() || !Logs::started()) {\
Logs::writeTcp(QString msg);\

@ -1 +1 @@
Subproject commit 443b7b6b650e48a7852515e9546d543e59459f97
Subproject commit 053ab218dfb65e9cbd7c7a1d9594fa886ba27f0b

@ -1 +1 @@
Subproject commit 5ae68777478250c49520629420290f231173e1ca
Subproject commit d35fe8aa38a26bfcefd32286d48c371e1c7317b0

@ -1 +1 @@
Subproject commit a37e28d2f3bb7ef306ce1b54db3cace902d363e6
Subproject commit 98e3ba2c582a0eeb6d0474c4c6b2ccd814fa8d54