Refactoring/service logging functional (#793)

This commit is contained in:
Garegin Harutyunyan 2024-08-08 19:13:49 +04:00 committed by GitHub
parent 1343d10aa7
commit 264d77463d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 38 additions and 5 deletions

View file

@ -161,13 +161,15 @@ void AmneziaApplication::init()
m_engine->load(url); m_engine->load(url);
m_systemController->setQmlRoot(m_engine->rootObjects().value(0)); m_systemController->setQmlRoot(m_engine->rootObjects().value(0));
bool enabled = m_settings->isSaveLogs();
#ifndef Q_OS_ANDROID #ifndef Q_OS_ANDROID
if (m_settings->isSaveLogs()) { if (enabled) {
if (!Logger::init()) { if (!Logger::init()) {
qWarning() << "Initialization of debug subsystem failed"; qWarning() << "Initialization of debug subsystem failed";
} }
} }
#endif #endif
Logger::setServiceLogsEnabled(enabled);
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
if (m_parser.isSet("a")) if (m_parser.isSet("a"))

View file

@ -99,6 +99,29 @@ void Logger::deInit()
m_file.close(); m_file.close();
} }
bool Logger::setServiceLogsEnabled(bool enabled) {
#ifdef AMNEZIA_DESKTOP
IpcClient *m_IpcClient = new IpcClient;
if (!m_IpcClient->isSocketConnected()) {
if (!IpcClient::init(m_IpcClient)) {
qWarning() << "Error occurred when init IPC client";
return false;
}
}
if (m_IpcClient->Interface()) {
m_IpcClient->Interface()->setLogsEnabled(enabled);
}
else {
qWarning() << "Error occurred setting up service logs";
return false;
}
#endif
return true;
}
QString Logger::userLogsDir() QString Logger::userLogsDir()
{ {
return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/log"; return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/log";
@ -141,7 +164,9 @@ bool Logger::openLogsFolder()
bool Logger::openServiceLogsFolder() bool Logger::openServiceLogsFolder()
{ {
QString path = Utils::systemLogPath(); QString path = Utils::systemLogPath();
#ifdef Q_OS_WIN
path = "file:///" + path; path = "file:///" + path;
#endif
QDesktopServices::openUrl(QUrl::fromLocalFile(path)); QDesktopServices::openUrl(QUrl::fromLocalFile(path));
return true; return true;
} }
@ -184,8 +209,7 @@ void Logger::clearServiceLogs()
} }
if (m_IpcClient->Interface()) { if (m_IpcClient->Interface()) {
m_IpcClient->Interface()->setLogsEnabled(false); m_IpcClient->Interface()->clearLogs();
m_IpcClient->Interface()->cleanUp();
} }
else { else {
qWarning() << "Error occurred cleaning up service logs"; qWarning() << "Error occurred cleaning up service logs";

View file

@ -26,6 +26,7 @@ public:
static bool init(); static bool init();
static void deInit(); static void deInit();
static bool setServiceLogsEnabled(bool enabled);
static bool openLogsFolder(); static bool openLogsFolder();
static bool openServiceLogsFolder(); static bool openServiceLogsFolder();
static QString appLogFileNamePath(); static QString appLogFileNamePath();

View file

@ -226,6 +226,8 @@ void Settings::setSaveLogs(bool enabled)
} }
} }
#endif #endif
Logger::setServiceLogsEnabled(enabled);
if (enabled) { if (enabled) {
setLogEnableDate(QDateTime::currentDateTime()); setLogEnableDate(QDateTime::currentDateTime());
} }

View file

@ -21,6 +21,7 @@ class IpcInterface
SLOT( void cleanUp() ); SLOT( void cleanUp() );
SLOT( void setLogsEnabled(bool enabled) ); SLOT( void setLogsEnabled(bool enabled) );
SLOT( void clearLogs() );
SLOT( bool createTun(const QString &dev, const QString &subnet) ); SLOT( bool createTun(const QString &dev, const QString &subnet) );
SLOT( bool deleteTun(const QString &dev) ); SLOT( bool deleteTun(const QString &dev) );

View file

@ -162,6 +162,10 @@ void IpcServer::cleanUp()
Logger::cleanUp(); Logger::cleanUp();
} }
void IpcServer::clearLogs() {
Logger::clearLogs();
}
bool IpcServer::createTun(const QString &dev, const QString &subnet) bool IpcServer::createTun(const QString &dev, const QString &subnet)
{ {
return Router::createTun(dev, subnet); return Router::createTun(dev, subnet);

View file

@ -26,6 +26,7 @@ public:
virtual bool checkAndInstallDriver() override; virtual bool checkAndInstallDriver() override;
virtual QStringList getTapList() override; virtual QStringList getTapList() override;
virtual void cleanUp() override; virtual void cleanUp() override;
virtual void clearLogs() override;
virtual void setLogsEnabled(bool enabled) override; virtual void setLogsEnabled(bool enabled) override;
virtual bool createTun(const QString &dev, const QString &subnet) override; virtual bool createTun(const QString &dev, const QString &subnet) override;
virtual bool deleteTun(const QString &dev) override; virtual bool deleteTun(const QString &dev) override;

View file

@ -46,8 +46,6 @@ int main(int argc, char **argv)
{ {
Utils::initializePath(Utils::systemLogPath()); Utils::initializePath(Utils::systemLogPath());
Logger::init();
if (argc >= 2) { if (argc >= 2) {
qInfo() << "Started as console application"; qInfo() << "Started as console application";
return runApplication(argc, argv); return runApplication(argc, argv);