From 3b2948d4dde81ee8fcb9946fda55fdb308690f76 Mon Sep 17 00:00:00 2001 From: "vladimir.kuznetsov" Date: Wed, 28 Dec 2022 13:41:45 +0300 Subject: [PATCH] renamed debug class to logger --- client/amnezia_application.cpp | 8 ++-- client/client.pro | 4 +- client/core/servercontroller.cpp | 8 ++-- client/core/servercontroller.h | 2 +- client/{debug.cpp => logger.cpp} | 43 ++++++++++--------- client/{debug.h => logger.h} | 16 +++---- .../protocols/ikev2_vpn_protocol_windows.cpp | 2 +- client/protocols/openvpnprotocol.cpp | 2 +- client/protocols/shadowsocksvpnprotocol.cpp | 2 +- client/protocols/wireguardprotocol.cpp | 2 +- client/settings.cpp | 6 +-- client/ui/pages_logic/AppSettingsLogic.cpp | 10 ++--- client/ui/uilogic.cpp | 6 +-- 13 files changed, 56 insertions(+), 55 deletions(-) rename client/{debug.cpp => logger.cpp} (81%) rename client/{debug.h => logger.h} (80%) diff --git a/client/amnezia_application.cpp b/client/amnezia_application.cpp index 1ea2900c..588854d3 100644 --- a/client/amnezia_application.cpp +++ b/client/amnezia_application.cpp @@ -7,7 +7,7 @@ #include "core/servercontroller.h" -#include "debug.h" +#include "logger.h" #include "defines.h" #include @@ -99,7 +99,7 @@ void AmneziaApplication::init() QCoreApplication::exit(-1); }, Qt::QueuedConnection); - m_engine->rootContext()->setContextProperty("Debug", &Debug::Instance()); + m_engine->rootContext()->setContextProperty("Debug", &Logger::Instance()); m_uiLogic->registerPagesLogic(); #if defined(Q_OS_IOS) @@ -113,7 +113,7 @@ void AmneziaApplication::init() } if (m_settings->isSaveLogs()) { - if (!Debug::init()) { + if (!Logger::init()) { qWarning() << "Initialization of debug subsystem failed"; } } @@ -206,7 +206,7 @@ bool AmneziaApplication::parseCommands() m_parser.process(*this); if (m_parser.isSet(c_cleanup)) { - Debug::cleanUp(); + Logger::cleanUp(); QTimer::singleShot(100, this, [this]{ quit(); }); diff --git a/client/client.pro b/client/client.pro index 85f70c68..47b39c99 100644 --- a/client/client.pro +++ b/client/client.pro @@ -43,8 +43,8 @@ HEADERS += \ core/scripts_registry.h \ core/server_defs.h \ core/servercontroller.h \ - debug.h \ defines.h \ + logger.h \ managementserver.h \ platforms/ios/MobileUtils.h \ platforms/linux/leakdetector.h \ @@ -102,7 +102,7 @@ SOURCES += \ core/scripts_registry.cpp \ core/server_defs.cpp \ core/servercontroller.cpp \ - debug.cpp \ + logger.cpp \ main.cpp \ managementserver.cpp \ platforms/ios/MobileUtils.cpp \ diff --git a/client/core/servercontroller.cpp b/client/core/servercontroller.cpp index c7336b62..1b2d7f94 100644 --- a/client/core/servercontroller.cpp +++ b/client/core/servercontroller.cpp @@ -79,7 +79,7 @@ ErrorCode ServerController::runScript(const ServerCredentials &credentials, QStr } qDebug().noquote() << "EXEC" << lineToExec; - Debug::appendSshLog("Run command:" + lineToExec); + Logger::appendSshLog("Run command:" + lineToExec); QSharedPointer proc = client->createRemoteProcess(lineToExec.toUtf8()); @@ -105,7 +105,7 @@ ErrorCode ServerController::runScript(const ServerCredentials &credentials, QStr QString s = proc->readAllStandardOutput(); if (s != "." && !s.isEmpty()) { - Debug::appendSshLog("Output: " + s); + Logger::appendSshLog("Output: " + s); qDebug().noquote() << "stdout" << s; } if (cbReadStdOut) cbReadStdOut(s, proc); @@ -114,7 +114,7 @@ ErrorCode ServerController::runScript(const ServerCredentials &credentials, QStr QObject::connect(proc.data(), &SshRemoteProcess::readyReadStandardError, &wait, [proc, cbReadStdErr](){ QString s = proc->readAllStandardError(); if (s != "." && !s.isEmpty()) { - Debug::appendSshLog("Output: " + s); + Logger::appendSshLog("Output: " + s); qDebug().noquote() << "stderr" << s; } if (cbReadStdErr) cbReadStdErr(s, proc); @@ -140,7 +140,7 @@ ErrorCode ServerController::runContainerScript(const ServerCredentials &credenti const std::function)> &cbReadStdErr) { QString fileName = "/opt/amnezia/" + Utils::getRandomString(16) + ".sh"; - Debug::appendSshLog("Run container script for " + ContainerProps::containerToString(container) + ":\n" + script); + Logger::appendSshLog("Run container script for " + ContainerProps::containerToString(container) + ":\n" + script); ErrorCode e = uploadTextFileToContainer(container, credentials, script, fileName); if (e) return e; diff --git a/client/core/servercontroller.h b/client/core/servercontroller.h index 091eaa52..9e8f4e40 100644 --- a/client/core/servercontroller.h +++ b/client/core/servercontroller.h @@ -5,7 +5,7 @@ #include #include "sshconnection.h" #include "sshremoteprocess.h" -#include "debug.h" +#include "logger.h" #include "defs.h" #include "containers/containers_defs.h" diff --git a/client/debug.cpp b/client/logger.cpp similarity index 81% rename from client/debug.cpp rename to client/logger.cpp index ebc27968..9b217218 100644 --- a/client/debug.cpp +++ b/client/logger.cpp @@ -1,3 +1,5 @@ +#include "logger.h" + #include #include #include @@ -7,7 +9,6 @@ #include -#include "debug.h" #include "defines.h" #include "utilities.h" @@ -15,9 +16,9 @@ #include #endif -QFile Debug::m_file; -QTextStream Debug::m_textStream; -QString Debug::m_logFileName = QString("%1.log").arg(APPLICATION_NAME); +QFile Logger::m_file; +QTextStream Logger::m_textStream; +QString Logger::m_logFileName = QString("%1.log").arg(APPLICATION_NAME); void debugMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg) { @@ -30,32 +31,32 @@ void debugMessageHandler(QtMsgType type, const QMessageLogContext& context, cons return; } - Debug::m_textStream << qFormatLogMessage(type, context, msg) << Qt::endl << Qt::flush; - Debug::appendAllLog(qFormatLogMessage(type, context, msg)); + Logger::m_textStream << qFormatLogMessage(type, context, msg) << Qt::endl << Qt::flush; + Logger::appendAllLog(qFormatLogMessage(type, context, msg)); std::cout << qFormatLogMessage(type, context, msg).toStdString() << std::endl << std::flush; } -Debug &Debug::Instance() +Logger &Logger::Instance() { - static Debug s; + static Logger s; return s; } -void Debug::appendSshLog(const QString &log) +void Logger::appendSshLog(const QString &log) { QString dt = QDateTime::currentDateTime().toString(); Instance().m_sshLog.append(dt + ": " + log + "\n"); emit Instance().sshLogChanged(Instance().sshLog()); } -void Debug::appendAllLog(const QString &log) +void Logger::appendAllLog(const QString &log) { Instance().m_allLog.append(log + "\n"); emit Instance().allLogChanged(Instance().allLog()); } -bool Debug::init() +bool Logger::init() { qSetMessagePattern("%{time yyyy-MM-dd hh:mm:ss} %{type} %{message}"); @@ -80,7 +81,7 @@ bool Debug::init() return true; } -void Debug::deInit() +void Logger::deInit() { qInstallMessageHandler(0); qSetMessagePattern("%{message}"); @@ -88,17 +89,17 @@ void Debug::deInit() m_file.close(); } -QString Debug::userLogsDir() +QString Logger::userLogsDir() { return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/log"; } -QString Debug::userLogsFilePath() +QString Logger::userLogsFilePath() { return userLogsDir() + QDir::separator() + m_logFileName; } -QString Debug::getLogFile() +QString Logger::getLogFile() { m_file.flush(); QFile file(userLogsFilePath()); @@ -107,7 +108,7 @@ QString Debug::getLogFile() return file.readAll(); } -bool Debug::openLogsFolder() +bool Logger::openLogsFolder() { QString path = userLogsDir(); #ifdef Q_OS_WIN @@ -120,7 +121,7 @@ bool Debug::openLogsFolder() return true; } -bool Debug::openServiceLogsFolder() +bool Logger::openServiceLogsFolder() { QString path = Utils::systemLogPath(); path = "file:///" + path; @@ -128,12 +129,12 @@ bool Debug::openServiceLogsFolder() return true; } -QString Debug::appLogFileNamePath() +QString Logger::appLogFileNamePath() { return m_file.fileName(); } -void Debug::clearLogs() +void Logger::clearLogs() { bool isLogActive = m_file.isOpen(); m_file.close(); @@ -149,7 +150,7 @@ void Debug::clearLogs() } } -void Debug::clearServiceLogs() +void Logger::clearServiceLogs() { #ifdef AMNEZIA_DESKTOP IpcClient *m_IpcClient = new IpcClient; @@ -171,7 +172,7 @@ void Debug::clearServiceLogs() #endif } -void Debug::cleanUp() +void Logger::cleanUp() { clearLogs(); QDir dir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); diff --git a/client/debug.h b/client/logger.h similarity index 80% rename from client/debug.h rename to client/logger.h index 5664b486..bea5213d 100644 --- a/client/debug.h +++ b/client/logger.h @@ -1,5 +1,5 @@ -#ifndef DEBUG_H -#define DEBUG_H +#ifndef LOGGER_H +#define LOGGER_H #include #include @@ -9,14 +9,14 @@ #include "ui/property_helper.h" -class Debug : public QObject +class Logger : public QObject { Q_OBJECT AUTO_PROPERTY(QString, sshLog) AUTO_PROPERTY(QString, allLog) public: - static Debug& Instance(); + static Logger& Instance(); static void appendSshLog(const QString &log); static void appendAllLog(const QString &log); @@ -35,9 +35,9 @@ public: static QString getLogFile(); private: - Debug() {} - Debug(Debug const &) = delete; - Debug& operator= (Debug const&) = delete; + Logger() {} + Logger(Logger const &) = delete; + Logger& operator= (Logger const&) = delete; static QString userLogsDir(); @@ -48,4 +48,4 @@ private: friend void debugMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg); }; -#endif // DEBUG_H +#endif // LOGGER_H diff --git a/client/protocols/ikev2_vpn_protocol_windows.cpp b/client/protocols/ikev2_vpn_protocol_windows.cpp index 44950f91..66c861d3 100644 --- a/client/protocols/ikev2_vpn_protocol_windows.cpp +++ b/client/protocols/ikev2_vpn_protocol_windows.cpp @@ -6,7 +6,7 @@ #include -#include "debug.h" +#include "logger.h" #include "ikev2_vpn_protocol_windows.h" #include "utilities.h" diff --git a/client/protocols/openvpnprotocol.cpp b/client/protocols/openvpnprotocol.cpp index fcce4ee6..150e84be 100644 --- a/client/protocols/openvpnprotocol.cpp +++ b/client/protocols/openvpnprotocol.cpp @@ -5,7 +5,7 @@ #include #include -#include "debug.h" +#include "logger.h" #include "defines.h" #include "utilities.h" #include "openvpnprotocol.h" diff --git a/client/protocols/shadowsocksvpnprotocol.cpp b/client/protocols/shadowsocksvpnprotocol.cpp index 6957bc3d..7e55b6f3 100644 --- a/client/protocols/shadowsocksvpnprotocol.cpp +++ b/client/protocols/shadowsocksvpnprotocol.cpp @@ -1,6 +1,6 @@ #include "shadowsocksvpnprotocol.h" -#include "debug.h" +#include "logger.h" #include "utilities.h" #include "containers/containers_defs.h" diff --git a/client/protocols/wireguardprotocol.cpp b/client/protocols/wireguardprotocol.cpp index 7f577ac5..985d835c 100644 --- a/client/protocols/wireguardprotocol.cpp +++ b/client/protocols/wireguardprotocol.cpp @@ -4,7 +4,7 @@ #include #include -#include "debug.h" +#include "logger.h" #include "wireguardprotocol.h" #include "utilities.h" diff --git a/client/settings.cpp b/client/settings.cpp index 08127ad1..efc63314 100644 --- a/client/settings.cpp +++ b/client/settings.cpp @@ -3,7 +3,7 @@ #include "utilities.h" #include "containers/containers_defs.h" -#include "debug.h" +#include "logger.h" const char Settings::cloudFlareNs1[] = "1.1.1.1"; const char Settings::cloudFlareNs2[] = "1.0.0.1"; @@ -211,9 +211,9 @@ void Settings::setSaveLogs(bool enabled) { m_settings.setValue("Conf/saveLogs", enabled); if (!isSaveLogs()) { - Debug::deInit(); + Logger::deInit(); } else { - if (!Debug::init()) { + if (!Logger::init()) { qWarning() << "Initialization of debug subsystem failed"; } } diff --git a/client/ui/pages_logic/AppSettingsLogic.cpp b/client/ui/pages_logic/AppSettingsLogic.cpp index b22918b2..3590c480 100644 --- a/client/ui/pages_logic/AppSettingsLogic.cpp +++ b/client/ui/pages_logic/AppSettingsLogic.cpp @@ -1,6 +1,6 @@ #include "AppSettingsLogic.h" -#include "debug.h" +#include "logger.h" #include "defines.h" #include "ui/qautostart.h" #include "ui/uilogic.h" @@ -62,18 +62,18 @@ void AppSettingsLogic::onCheckBoxSaveLogsCheckedToggled(bool checked) void AppSettingsLogic::onPushButtonOpenLogsClicked() { - Debug::openLogsFolder(); + Logger::openLogsFolder(); } void AppSettingsLogic::onPushButtonExportLogsClicked() { - uiLogic()->saveTextFile(tr("Save log"), "AmneziaVPN.log", ".log", Debug::getLogFile()); + uiLogic()->saveTextFile(tr("Save log"), "AmneziaVPN.log", ".log", Logger::getLogFile()); } void AppSettingsLogic::onPushButtonClearLogsClicked() { - Debug::clearLogs(); - Debug::clearServiceLogs(); + Logger::clearLogs(); + Logger::clearServiceLogs(); } void AppSettingsLogic::onPushButtonBackupAppConfigClicked() diff --git a/client/ui/uilogic.cpp b/client/ui/uilogic.cpp index e336fa76..061da41a 100644 --- a/client/ui/uilogic.cpp +++ b/client/ui/uilogic.cpp @@ -35,7 +35,7 @@ #include "ui/qautostart.h" -#include "debug.h" +#include "logger.h" #include "defines.h" #include "uilogic.h" #include "utilities.h" @@ -190,9 +190,9 @@ void UiLogic::keyPressEvent(Qt::Key key) case Qt::Key_AsciiTilde: case Qt::Key_QuoteLeft: emit toggleLogPanel(); break; - case Qt::Key_L: Debug::openLogsFolder(); + case Qt::Key_L: Logger::openLogsFolder(); break; - case Qt::Key_K: Debug::openServiceLogsFolder(); + case Qt::Key_K: Logger::openServiceLogsFolder(); break; #ifdef QT_DEBUG case Qt::Key_Q: