diff --git a/ext/ghoul b/ext/ghoul index 597d87c289..34492c0dfe 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 597d87c289a440c7230b12aefab5fcc6ed2a59cd +Subproject commit 34492c0dfe586fd24e0c8dbd515bd486704522cc diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index 7b11fb4013..362c660ded 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -85,6 +85,7 @@ private: bool loadSpiceKernels(); void runStartupScripts(); void loadFonts(); + void createLogs(); static OpenSpaceEngine* _engine; diff --git a/include/openspace/util/constants.h b/include/openspace/util/constants.h index b22a100b55..ec0ac6d9d8 100644 --- a/include/openspace/util/constants.h +++ b/include/openspace/util/constants.h @@ -48,6 +48,8 @@ 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 keyLogType = "Type"; } // namespace configurationmanager namespace scenegraph { diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 70b24dd05b..4bbf870dee 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -42,8 +42,7 @@ // ghoul #include #include -#include -#include +#include #include #include #include @@ -220,13 +219,40 @@ void OpenSpaceEngine::loadFonts() { } } +void OpenSpaceEngine::createLogs() { + using constants::configurationmanager::keyLogs; + using constants::configurationmanager::keyLogType; + + if (_engine->configurationManager().hasKeyAndValue(keyLogs)) { + ghoul::TemplateFactory logFactory; + logFactory.registerClass("HTML"); + logFactory.registerClass("Text"); + + ghoul::Dictionary logs; + _engine->configurationManager().getValue(keyLogs, logs); + + for (size_t i = 1; i <= logs.size(); ++i) { + ghoul::Dictionary logInfo; + logs.getValue(std::to_string(i), logInfo); + + std::string type; + logInfo.getValue(keyLogType, type); + + ghoul::logging::Log* log = logFactory.create(type, logInfo); + LogMgr.addLog(log); + } + } +} + bool OpenSpaceEngine::create(int argc, char** argv, std::vector& sgctArguments) { // TODO custom assert (ticket #5) assert(_engine == nullptr); - // initialize Ghoul classes + // 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 LogManager::initialize(LogManager::LogLevel::Debug, true); LogMgr.addLog(new ConsoleLog); ghoul::filesystem::FileSystem::initialize(); @@ -253,7 +279,6 @@ bool OpenSpaceEngine::create(int argc, char** argv, if (!executeSuccess) return false; - // Find configuration std::string configurationFilePath = commandlineArgumentPlaceholders.configurationName; if (configurationFilePath.empty()) { @@ -276,7 +301,10 @@ bool OpenSpaceEngine::create(int argc, char** argv, return false; } - // Create directories that doesn't exsist + // Initialize the requested logs from the configuration file + _engine->createLogs(); + + // Create directories that doesn't exist auto tokens = FileSys.tokens(); for (auto token : tokens) { if (!FileSys.directoryExists(token)) {