Adding capabilities to configure the LogLevel and ImmediateFlush of the LogManager

This commit is contained in:
Alexander Bock
2014-12-05 16:43:54 +01:00
parent cf53b5c1b0
commit d9fbf7c5fd
4 changed files with 32 additions and 12 deletions

View File

@@ -85,7 +85,7 @@ private:
bool loadSpiceKernels();
void runStartupScripts();
void loadFonts();
void createLogs();
void configureLogging();
static OpenSpaceEngine* _engine;

View File

@@ -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 {

View File

@@ -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 = {

View File

@@ -232,9 +232,26 @@ void OpenSpaceEngine::loadFonts() {
}
}
void OpenSpaceEngine::createLogs() {
void OpenSpaceEngine::configureLogging() {
using constants::configurationmanager::keyLogLevel;
using constants::configurationmanager::keyLogs;
if (configurationManager().hasKeyAndValue<std::string>(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<ghoul::Dictionary>(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();