logic: Enable/Disable Logging in Preferences

* disabled by default
This commit is contained in:
Eberhard Graether
2016-08-25 13:44:43 +02:00
parent 03bbce45c9
commit bff9430fa2
12 changed files with 76 additions and 43 deletions
@@ -18,17 +18,19 @@
<font_size_min><!-- INTEGER: minimum font size in pt --></font_size_min>
<font_size_std><!-- INTEGER: standard font size in pt --></font_size_std>
<show_external_non_fatal_errors><!-- BOOL: show non-fatal errors in unindexed files --></show_external_non_fatal_errors>
<window_base_width><!-- INTEGER: initial width of an overlay window --></window_base_width>
<window_base_height><!-- INTEGER: initial height of an overlay window --></window_base_height>
<scroll_speed><!-- DECIMAL: multiplier for default scroll speed in views --></scroll_speed>
<logging_enabled><!-- BOOL: define if console and file logging is enabled --></logging_enabled>
</application>
<indexing>
<indexer_thread_count><!-- INTEGER: number of threads indexing the source code --></indexer_thread_count>
<show_external_non_fatal_errors><!-- BOOL: show non-fatal errors in unindexed files --></show_external_non_fatal_errors>
<cxx>
<compiler_flags>
<compiler_flag><!-- STRING: compiler flag, including the dash e.g. -v --></compiler_flag>
+3 -19
View File
@@ -1,8 +1,5 @@
#include "utility/AppPath.h"
#include "utility/commandline/CommandLineParser.h"
#include "utility/logging/ConsoleLogger.h"
#include "utility/logging/FileLogger.h"
#include "utility/logging/LogManager.h"
#include "utility/ResourcePaths.h"
#include "utility/ScopedFunctor.h"
#include "utility/UserPaths.h"
@@ -19,18 +16,6 @@
#include "qt/window/QtMainWindow.h"
#include "version.h"
void init()
{
std::shared_ptr<ConsoleLogger> consoleLogger = std::make_shared<ConsoleLogger>();
consoleLogger->setLogLevel(Logger::LOG_WARNINGS | Logger::LOG_ERRORS);
LogManager::getInstance()->addLogger(consoleLogger);
std::shared_ptr<FileLogger> fileLogger = std::make_shared<FileLogger>();
fileLogger->setLogLevel(Logger::LOG_ALL);
FileLogger::setFilePath(UserPaths::getLogPath());
LogManager::getInstance()->addLogger(fileLogger);
}
int main(int argc, char *argv[])
{
QApplication::setApplicationName("Coati");
@@ -57,7 +42,6 @@ int main(int argc, char *argv[])
QtCoreApplication qtApp(argc, argv);
setupApp(argc, argv);
init();
Application::createInstance(version, nullptr, nullptr);
ScopedFunctor f([](){
@@ -88,15 +72,12 @@ int main(int argc, char *argv[])
QtApplication qtApp(argc, argv);
setupApp(argc, argv);
init();
qtApp.setAttribute(Qt::AA_UseHighDpiPixmaps);
QtViewFactory viewFactory;
QtNetworkFactory networkFactory;
utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".otf");
utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".ttf");
Application::createInstance(version, &viewFactory, &networkFactory);
ScopedFunctor f([](){
Application::destroyInstance();
@@ -104,6 +85,9 @@ int main(int argc, char *argv[])
commandLineParser.projectLoad();
utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".otf");
utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".ttf");
return qtApp.exec();
}
}
+20
View File
@@ -1,7 +1,10 @@
#include "Application.h"
#include "utility/file/FileSystem.h"
#include "utility/logging/ConsoleLogger.h"
#include "utility/logging/FileLogger.h"
#include "utility/logging/logging.h"
#include "utility/logging/LogManager.h"
#include "utility/messaging/MessageQueue.h"
#include "utility/messaging/type/MessageActivateNodes.h"
#include "utility/messaging/type/MessageDispatchWhenLicenseValid.h"
@@ -75,6 +78,23 @@ void Application::loadSettings()
std::shared_ptr<ApplicationSettings> settings = ApplicationSettings::getInstance();
settings->load(FilePath(UserPaths::getAppSettingsPath()));
LogManager* logManager = LogManager::getInstance().get();
if (settings->getLoggingEnabled() && !logManager->getLoggerCount())
{
std::shared_ptr<ConsoleLogger> consoleLogger = std::make_shared<ConsoleLogger>();
// consoleLogger->setLogLevel(Logger::LOG_WARNINGS | Logger::LOG_ERRORS);
logManager->addLogger(consoleLogger);
FileLogger::setFilePath(UserPaths::getLogPath());
std::shared_ptr<FileLogger> fileLogger = std::make_shared<FileLogger>();
fileLogger->setLogLevel(Logger::LOG_ALL);
logManager->addLogger(fileLogger);
}
else
{
logManager->clearLoggers();
}
loadStyle(settings->getColorSchemePath());
}
+12 -2
View File
@@ -155,6 +155,16 @@ void ApplicationSettings::setScrollSpeed(float scrollSpeed)
setValue<float>("application/scroll_speed", scrollSpeed);
}
bool ApplicationSettings::getLoggingEnabled() const
{
return getValue<float>("application/logging_enabled", false);
}
void ApplicationSettings::setLoggingEnabled(bool loggingEnabled)
{
setValue<bool>("application/logging_enabled", loggingEnabled);
}
int ApplicationSettings::getIndexerThreadCount() const
{
return getValue<int>("indexing/indexer_thread_count", 4);
@@ -167,12 +177,12 @@ void ApplicationSettings::setIndexerThreadCount(const int count)
bool ApplicationSettings::getShowExternalNonFatalErrors() const
{
return getValue<bool>("application/show_external_non_fatal_errors", false);
return getValue<bool>("indexing/show_external_non_fatal_errors", false);
}
void ApplicationSettings::setShowExternalNonFatalErrors(const bool show)
{
setValue<bool>("application/show_external_non_fatal_errors", show);
setValue<bool>("indexing/show_external_non_fatal_errors", show);
}
std::string ApplicationSettings::getJavaPath() const
+3
View File
@@ -47,6 +47,9 @@ public:
float getScrollSpeed() const;
void setScrollSpeed(float scrollSpeed);
bool getLoggingEnabled() const;
void setLoggingEnabled(bool loggingEnabled);
// indexing
int getIndexerThreadCount() const;
void setIndexerThreadCount(const int count);
+5
View File
@@ -39,6 +39,11 @@ void LogManager::removeLoggersByType(const std::string& type)
m_logManagerImplementation.removeLoggersByType(type);
}
void LogManager::clearLoggers()
{
m_logManagerImplementation.clearLoggers();
}
int LogManager::getLoggerCount() const
{
return m_logManagerImplementation.getLoggerCount();
+1
View File
@@ -18,6 +18,7 @@ public:
void addLogger(std::shared_ptr<Logger> logger);
void removeLogger(std::shared_ptr<Logger> logger);
void removeLoggersByType(const std::string& type);
void clearLoggers();
int getLoggerCount() const;
void logInfo(
@@ -49,6 +49,11 @@ void LogManagerImplementation::removeLoggersByType(const std::string& type)
}
}
void LogManagerImplementation::clearLoggers()
{
m_loggers.clear();
}
int LogManagerImplementation::getLoggerCount() const
{
std::lock_guard<std::mutex> lockGuard(m_loggerMutex);
@@ -24,6 +24,7 @@ public:
void addLogger(std::shared_ptr<Logger> logger);
void removeLogger(std::shared_ptr<Logger> logger);
void removeLoggersByType(const std::string& type);
void clearLoggers();
int getLoggerCount() const;
void logInfo(
@@ -99,6 +99,19 @@ void QtProjectWizzardContentPreferences::populateForm(QGridLayout* layout, int&
);
row++;
// logging
m_loggingEnabled = new QCheckBox("Enable console and file logging", this);
layout->addWidget(createFormLabel("Logging"), row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight);
layout->addWidget(m_loggingEnabled, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignLeft);
addHelpButton(
"Save log files and show log information in the console."
, layout, row
);
row++;
layout->setRowMinimumHeight(row++, 20);
// indexing
@@ -191,6 +204,7 @@ void QtProjectWizzardContentPreferences::load()
}
m_scrollSpeed->setText(QString::number(appSettings->getScrollSpeed(), 'f', 1));
m_loggingEnabled->setChecked(appSettings->getLoggingEnabled());
m_threads->setCurrentIndex(appSettings->getIndexerThreadCount() - 1);
m_fatalErrors->setChecked(appSettings->getShowExternalNonFatalErrors());
@@ -219,6 +233,8 @@ void QtProjectWizzardContentPreferences::save()
appSettings->setScrollSpeed(scrollSpeed);
}
appSettings->setLoggingEnabled(m_loggingEnabled->isChecked());
appSettings->setIndexerThreadCount(m_threads->currentIndex() + 1);
appSettings->setShowExternalNonFatalErrors(m_fatalErrors->isChecked());
@@ -38,10 +38,12 @@ private:
QComboBox* m_tabWidth;
QComboBox* m_colorSchemes;
QLineEdit* m_scrollSpeed;
std::vector<FilePath> m_colorSchemePaths;
int m_oldColorSchemeIndex;
QLineEdit* m_scrollSpeed;
QCheckBox* m_loggingEnabled;
QComboBox* m_threads;
QCheckBox* m_fatalErrors;
+3 -19
View File
@@ -1,7 +1,4 @@
#include "utility/AppPath.h"
#include "utility/logging/ConsoleLogger.h"
#include "utility/logging/FileLogger.h"
#include "utility/logging/LogManager.h"
#include "utility/ResourcePaths.h"
#include "utility/ScopedFunctor.h"
#include "utility/UserPaths.h"
@@ -16,18 +13,6 @@
#include "qt/window/QtMainWindow.h"
#include "version.h"
void init()
{
std::shared_ptr<ConsoleLogger> consoleLogger = std::make_shared<ConsoleLogger>();
consoleLogger->setLogLevel(Logger::LOG_WARNINGS | Logger::LOG_ERRORS);
LogManager::getInstance()->addLogger(consoleLogger);
std::shared_ptr<FileLogger> fileLogger = std::make_shared<FileLogger>();
fileLogger->setLogLevel(Logger::LOG_ALL);
FileLogger::setFilePath(UserPaths::getLogPath());
LogManager::getInstance()->addLogger(fileLogger);
}
int main(int argc, char *argv[])
{
QApplication::setApplicationName("Coati Trial");
@@ -45,20 +30,19 @@ int main(int argc, char *argv[])
QtApplication qtApp(argc, argv);
setupApp(argc, argv);
init();
qtApp.setAttribute(Qt::AA_UseHighDpiPixmaps);
QtViewFactory viewFactory;
QtNetworkFactory networkFactory;
utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".otf");
utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".ttf");
Application::createInstance(version, &viewFactory, &networkFactory);
ScopedFunctor f([](){
Application::destroyInstance();
});
utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".otf");
utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".ttf");
return qtApp.exec();
}