From d9fbf7c5fd3b1ef4e6ff3d6772ee17d924b56010 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Fri, 5 Dec 2014 16:43:54 +0100 Subject: [PATCH] Adding capabilities to configure the LogLevel and ImmediateFlush of the LogManager --- include/openspace/engine/openspaceengine.h | 2 +- include/openspace/util/constants.h | 4 +++- openspace.cfg | 11 ++++----- src/engine/openspaceengine.cpp | 27 ++++++++++++++++++---- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index 362c660ded..0fbcbf5eda 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -85,7 +85,7 @@ private: bool loadSpiceKernels(); void runStartupScripts(); void loadFonts(); - void createLogs(); + void configureLogging(); static OpenSpaceEngine* _engine; diff --git a/include/openspace/util/constants.h b/include/openspace/util/constants.h index 8de1f285be..d7191e2fed 100644 --- a/include/openspace/util/constants.h +++ b/include/openspace/util/constants.h @@ -48,7 +48,9 @@ namespace configurationmanager { const std::string keyStartupScript = "StartupScripts"; const std::string keySpiceTimeKernel = "SpiceKernel.Time"; const std::string keySpiceLeapsecondKernel = "SpiceKernel.LeapSecond"; - const std::string keyLogs = "Logs"; + const std::string keyLogLevel = "Logging.LogLevel"; + const std::string keyLogImmediateFlush = "Logging.ImmediateFlush"; + const std::string keyLogs = "Logging.Logs"; } // namespace configurationmanager namespace scenegraph { diff --git a/openspace.cfg b/openspace.cfg index 3f9a84c46c..6ad494e50c 100644 --- a/openspace.cfg +++ b/openspace.cfg @@ -8,7 +8,6 @@ return { TESTDIR = "${BASE_PATH}/src/tests", CONFIG = "${BASE_PATH}/config", CACHE = "${BASE_PATH}/cache", - TEMPORARY = "${BASE_PATH}/tmp", FONTS = "${OPENSPACE_DATA}/fonts" }, SpiceKernel = { @@ -27,11 +26,11 @@ return { StartupScripts = { "${SCRIPTS}/default_startup.lua" }, - Logs = { - { - Type = "HTML", - FileName = "${BASE_PATH}/log.html", - Append = false + Logging = { + LogLevel = "Warning", + ImmediateFlush = true, + Logs = { + { Type = "HTML", FileName = "${BASE_PATH}/log.html", Append = false } } }, LuaDocumentationFile = { diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index fbcb8b1d58..c6105458c9 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -232,9 +232,26 @@ void OpenSpaceEngine::loadFonts() { } } -void OpenSpaceEngine::createLogs() { +void OpenSpaceEngine::configureLogging() { + using constants::configurationmanager::keyLogLevel; using constants::configurationmanager::keyLogs; + if (configurationManager().hasKeyAndValue(keyLogLevel)) { + using constants::configurationmanager::keyLogLevel; + using constants::configurationmanager::keyLogImmediateFlush; + + std::string logLevel; + configurationManager().getValue(keyLogLevel, logLevel); + + bool immediateFlush = false; + configurationManager().getValue(keyLogImmediateFlush, immediateFlush); + + LogManager::LogLevel level = LogManager::levelFromString(logLevel); + LogManager::deinitialize(); + LogManager::initialize(level, immediateFlush); + LogMgr.addLog(new ConsoleLog); + } + if (configurationManager().hasKeyAndValue(keyLogs)) { ghoul::Dictionary logs; configurationManager().getValue(keyLogs, logs); @@ -257,9 +274,11 @@ bool OpenSpaceEngine::create(int argc, char** argv, // TODO custom assert (ticket #5) assert(_engine == nullptr); - // Initialize the Logmanager and add the console log as this will be used every time + // Initialize the LogManager and add the console log as this will be used every time // and we need a fall back if something goes wrong between here and when we add the - // logs from the configuration file + // logs from the configuration file. If the user requested as specific loglevel in the + // configuration file, we will deinitialize this LogManager and reinitialize it later + // with the correct LogLevel LogManager::initialize(LogManager::LogLevel::Debug, true); LogMgr.addLog(new ConsoleLog); ghoul::filesystem::FileSystem::initialize(); @@ -310,7 +329,7 @@ bool OpenSpaceEngine::create(int argc, char** argv, } // Initialize the requested logs from the configuration file - _engine->createLogs(); + _engine->configureLogging(); // Create directories that doesn't exist auto tokens = FileSys.tokens();