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_systemController->setQmlRoot(m_engine->rootObjects().value(0));
bool enabled = m_settings->isSaveLogs();
#ifndef Q_OS_ANDROID
if (m_settings->isSaveLogs()) {
if (enabled) {
if (!Logger::init()) {
qWarning() << "Initialization of debug subsystem failed";
}
}
#endif
Logger::setServiceLogsEnabled(enabled);
#ifdef Q_OS_WIN
if (m_parser.isSet("a"))

View file

@ -99,6 +99,29 @@ void Logger::deInit()
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()
{
return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/log";
@ -141,7 +164,9 @@ bool Logger::openLogsFolder()
bool Logger::openServiceLogsFolder()
{
QString path = Utils::systemLogPath();
#ifdef Q_OS_WIN
path = "file:///" + path;
#endif
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
return true;
}
@ -184,8 +209,7 @@ void Logger::clearServiceLogs()
}
if (m_IpcClient->Interface()) {
m_IpcClient->Interface()->setLogsEnabled(false);
m_IpcClient->Interface()->cleanUp();
m_IpcClient->Interface()->clearLogs();
}
else {
qWarning() << "Error occurred cleaning up service logs";

View file

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

View file

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