logic: Allow changing the log file path in preferences (issue #156) (#900)

This commit is contained in:
Waqar Ahmed
2020-02-03 10:54:52 +01:00
committed by GitHub
parent 9669dc1e71
commit f7923ebd75
8 changed files with 52 additions and 3 deletions
+1
View File
@@ -1,4 +1,5 @@
/build/
build-*
/distr/
/deps/
-2
View File
@@ -61,8 +61,6 @@ void setupLogging()
logManager->addLogger(consoleLogger);
std::shared_ptr<FileLogger> fileLogger = std::make_shared<FileLogger>();
fileLogger->setLogDirectory(UserPaths::getLogPath().getAbsolute());
fileLogger->setFileName(FileLogger::generateDatedFileName(L"log"));
fileLogger->setLogLevel(Logger::LOG_ALL);
fileLogger->deleteLogFiles(FileLogger::generateDatedFileName(L"log", L"", -30));
logManager->addLogger(fileLogger);
+8
View File
@@ -30,6 +30,7 @@
#include "tracing.h"
#include "utilityString.h"
#include "utilityUuid.h"
#include "FileLogger.h"
std::shared_ptr<Application> Application::s_instance;
std::string Application::s_uuid;
@@ -112,6 +113,13 @@ void Application::loadSettings()
settings->load(UserPaths::getAppSettingsPath());
LogManager::getInstance()->setLoggingEnabled(settings->getLoggingEnabled());
Logger* logger = LogManager::getInstance()->getLoggerByType("FileLogger");
if (logger)
{
const auto fileLogger = dynamic_cast<FileLogger*>(logger);
fileLogger->setLogDirectory(settings->getLogDirectoryPath());
fileLogger->setFileName(FileLogger::generateDatedFileName(L"log"));
}
loadStyle(settings->getColorSchemePath());
}
+11
View File
@@ -337,6 +337,17 @@ void ApplicationSettings::setVerboseIndexerLoggingEnabled(bool value)
setValue<bool>("application/verbose_indexer_logging_enabled", value);
}
FilePath ApplicationSettings::getLogDirectoryPath() const
{
return FilePath(getValue<std::wstring>(
"application/log_directory_path", UserPaths::getLogPath().getAbsolute().wstr()));
}
void ApplicationSettings::setLogDirectoryPath(const FilePath &path)
{
setValue<std::wstring>("application/log_directory_path", path.wstr());
}
void ApplicationSettings::setLogFilter(int mask)
{
setValue<int>("application/log_filter", mask);
+3
View File
@@ -82,6 +82,9 @@ public:
bool getVerboseIndexerLoggingEnabled() const;
void setVerboseIndexerLoggingEnabled(bool loggingEnabled);
FilePath getLogDirectoryPath() const;
void setLogDirectoryPath(const FilePath& path);
int getLogFilter() const;
void setLogFilter(int mask);
@@ -13,6 +13,7 @@
#include "MessageSwitchColorScheme.h"
#include "ResourcePaths.h"
#include "logging.h"
#include "FileLogger.h"
#include "utility.h"
#include "utilityApp.h"
#include "utilityPathDetection.h"
@@ -238,6 +239,16 @@ void QtProjectWizardContentPreferences::populate(QGridLayout* layout, int& row)
layout,
row);
m_logPath = new QtLocationPicker(this);
m_logPath->setPickDirectory(true);
addLabelAndWidget(QStringLiteral("Log Directory Path"), m_logPath, layout, row);
addHelpButton(
QStringLiteral("Log Directory Path"),
QStringLiteral("<p>Log file will be saved to this path.</p>"),
layout,
row);
row++;
addGap(layout, row);
// Network
@@ -488,6 +499,10 @@ void QtProjectWizardContentPreferences::load()
m_loggingEnabled->setChecked(appSettings->getLoggingEnabled());
m_verboseIndexerLoggingEnabled->setChecked(appSettings->getVerboseIndexerLoggingEnabled());
m_verboseIndexerLoggingEnabled->setEnabled(m_loggingEnabled->isChecked());
if (m_logPath)
{
m_logPath->setText(QString::fromStdWString(appSettings->getLogDirectoryPath().wstr()));
}
m_automaticUpdateCheck->setChecked(appSettings->getAutomaticUpdateCheck());
@@ -551,6 +566,17 @@ void QtProjectWizardContentPreferences::save()
appSettings->setLoggingEnabled(m_loggingEnabled->isChecked());
appSettings->setVerboseIndexerLoggingEnabled(m_verboseIndexerLoggingEnabled->isChecked());
if (m_logPath && m_logPath->getText().toStdWString() != appSettings->getLogDirectoryPath().wstr())
{
appSettings->setLogDirectoryPath(FilePath((m_logPath->getText() + '/').toStdWString()));
Logger* logger = LogManager::getInstance()->getLoggerByType("FileLogger");
if (logger)
{
const auto fileLogger = dynamic_cast<FileLogger*>(logger);
fileLogger->setLogDirectory(appSettings->getLogDirectoryPath());
fileLogger->setFileName(FileLogger::generateDatedFileName(L"log"));
}
}
appSettings->setAutomaticUpdateCheck(m_automaticUpdateCheck->isChecked());
@@ -114,6 +114,7 @@ private:
QCheckBox* m_loggingEnabled;
QCheckBox* m_verboseIndexerLoggingEnabled;
QtLocationPicker* m_logPath;
QCheckBox* m_automaticUpdateCheck;
+2 -1
View File
@@ -545,7 +545,8 @@ void QtMainWindow::showDataFolder()
void QtMainWindow::showLogFolder()
{
QDesktopServices::openUrl(QUrl(
QString::fromStdWString(L"file:///" + UserPaths::getLogPath().makeCanonical().wstr()),
QString::fromStdWString(
L"file:///" + ApplicationSettings::getInstance()->getLogDirectoryPath().wstr()),
QUrl::TolerantMode));
}