diff --git a/apps/Launcher/mainwindow.cpp b/apps/Launcher/mainwindow.cpp index 0a793c398b..502c97a400 100644 --- a/apps/Launcher/mainwindow.cpp +++ b/apps/Launcher/mainwindow.cpp @@ -62,7 +62,7 @@ namespace { class QLog : public ghoul::logging::Log { public: void log( - ghoul::logging::LogManager::LogLevel level, + ghoul::logging::LogLevel level, const std::string& category, const std::string& message ) { @@ -189,7 +189,7 @@ void MainWindow::initialize() { _syncWidget->setWindowModality(Qt::WindowModal); _syncWidget->hide(); - ghoul::logging::LogManager::initialize(ghoul::logging::LogManager::LogLevel::Debug); + ghoul::logging::LogManager::initialize(ghoul::logging::LogLevel::Debug); LogMgr.addLog( std::make_unique< ghoul::logging::ConsoleLog >() ); // TODO: This can crash the system in cases where the logfile can't be created ---abock LogMgr.addLog( std::make_unique< ghoul::logging::HTMLLog >("LauncherLog.html", ghoul::logging::HTMLLog::Append::No) ); diff --git a/ext/ghoul b/ext/ghoul index ec91abd773..f341d33a3b 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit ec91abd77337c62eb99eee593e5046ddfa0d65d0 +Subproject commit f341d33a3bf968d7d6304039a111ad295b315939 diff --git a/include/openspace/util/screenlog.h b/include/openspace/util/screenlog.h index b6bea017de..f800991555 100644 --- a/include/openspace/util/screenlog.h +++ b/include/openspace/util/screenlog.h @@ -42,14 +42,14 @@ namespace openspace { class ScreenLog : public ghoul::logging::Log { public: /// Just a shortcut for the LogLevel access - using LogLevel = ghoul::logging::LogManager::LogLevel; + using LogLevel = ghoul::logging::LogLevel; /** * This struct stores the incoming log entries with their #level, #timeString, * #category, #message, and the generated #timeStamp used for the expiry calculation. */ struct LogEntry { - /// The ghoul::logging::LogManager::LogLevel of the log message + /// The ghoul::logging::LogLevel of the log message LogLevel level; /// The timepoint when the log message arrived at the ScreenLog @@ -68,10 +68,10 @@ public: /** * Constructor that creates a ScreenLog with the provided \p timeToLive, and the * minimum \p logLevel that is stored. Log message with a lower - * ghoul::logging::LogManager::LogLevel are automatically discarded. + * ghoul::logging::LogLevel are automatically discarded. * \param timeToLive The time-to-live for the messages in this ScreenLog. Expired * messages are removed whenever the #removeExpiredEntries method is called - * \param logLevel The minimum ghoul::logging::LogManager::LogLevel that messages must + * \param logLevel The minimum ghoul::logging::LogLevel that messages must * have in order to be stored in the ScreenLog */ ScreenLog(std::chrono::seconds timeToLive, LogLevel logLevel = LogLevel::Info); @@ -79,11 +79,11 @@ public: /** * Overwritten ghoul::loggling::Log method that is called whenever a new log message * shall be stored. - * \param level The ghoul::logging::LogManager::LogLevel of the incoming log message + * \param level The ghoul::logging::LogLevel of the incoming log message * \param category The category of the log message * \param message The actual log message that was transmitted */ - void log(ghoul::logging::LogManager::LogLevel level, const std::string& category, + void log(ghoul::logging::LogLevel level, const std::string& category, const std::string& message) override; /** diff --git a/src/engine/logfactory.cpp b/src/engine/logfactory.cpp index c1ec813a07..7cf10928ee 100644 --- a/src/engine/logfactory.cpp +++ b/src/engine/logfactory.cpp @@ -27,34 +27,37 @@ #include #include #include +#include #include #include namespace { - const std::string keyType = "Type"; - const std::string keyFilename = "File"; - const std::string keyAppend = "Append"; - const std::string keyTimeStamping = "TimeStamping"; - const std::string keyDateStamping = "DateStamping"; - const std::string keyCategoryStamping = "CategoryStamping"; - const std::string keyLogLevelStamping = "LogLevelStamping"; + const char* keyType = "Type"; + const char* keyFilename = "File"; + const char* keyAppend = "Append"; + const char* keyTimeStamping = "TimeStamping"; + const char* keyDateStamping = "DateStamping"; + const char* keyCategoryStamping = "CategoryStamping"; + const char* keyLogLevelStamping = "LogLevelStamping"; + const char* keyLogLevel = "LogLevel"; - const std::string valueHtmlLog = "html"; - const std::string valueTextLog = "Text"; + const char* valueHtmlLog = "html"; + const char* valueTextLog = "Text"; - const std::string BootstrapPath = "${OPENSPACE_DATA}/web/common/bootstrap.min.css"; - const std::string CssPath = "${OPENSPACE_DATA}/web/log/style.css"; - const std::string JsPath = "${OPENSPACE_DATA}/web/log/script.js"; + const char* BootstrapPath = "${OPENSPACE_DATA}/web/common/bootstrap.min.css"; + const char* CssPath = "${OPENSPACE_DATA}/web/log/style.css"; + const char* JsPath = "${OPENSPACE_DATA}/web/log/script.js"; } namespace openspace { std::unique_ptr createLog(const ghoul::Dictionary& dictionary) { + using namespace std::string_literals; std::string type; bool typeSuccess = dictionary.getValue(keyType, type); if (!typeSuccess) { throw ghoul::RuntimeError( - "Requested log did not contain key '" + keyType + "'", "LogFactory" + "Requested log did not contain key '"s + keyType + "'", "LogFactory" ); } @@ -62,7 +65,7 @@ std::unique_ptr createLog(const ghoul::Dictionary& dictiona bool filenameSuccess = dictionary.getValue(keyFilename, filename); if (!filenameSuccess) { throw ghoul::RuntimeError( - "Requested log did not contain key '" + keyFilename + "'", "LogFactory" + "Requested log did not contain key '"s + keyFilename + "'", "LogFactory" ); } filename = absPath(filename); @@ -77,6 +80,8 @@ std::unique_ptr createLog(const ghoul::Dictionary& dictiona dictionary.getValue(keyCategoryStamping, categoryStamp); bool logLevelStamp = true; dictionary.getValue(keyLogLevelStamping, logLevelStamp); + std::string logLevel; + dictionary.getValue(keyLogLevel, logLevel); using Append = ghoul::logging::TextLog::Append; using TimeStamping = ghoul::logging::Log::TimeStamping; @@ -89,25 +94,52 @@ std::unique_ptr createLog(const ghoul::Dictionary& dictiona std::vector cssFiles{absPath(BootstrapPath), absPath(CssPath)}; std::vector jsFiles{absPath(JsPath)}; - return std::make_unique( - filename, - append ? Append::Yes : Append::No, - timeStamp ? TimeStamping::Yes : TimeStamping::No, - dateStamp ? DateStamping::Yes : DateStamping::No, - categoryStamp ? CategoryStamping::Yes : CategoryStamping::No, - logLevelStamp ? LogLevelStamping::Yes : LogLevelStamping::No, - cssFiles, jsFiles - ); + if (logLevel.empty()) { + return std::make_unique( + filename, + append ? Append::Yes : Append::No, + timeStamp ? TimeStamping::Yes : TimeStamping::No, + dateStamp ? DateStamping::Yes : DateStamping::No, + categoryStamp ? CategoryStamping::Yes : CategoryStamping::No, + logLevelStamp ? LogLevelStamping::Yes : LogLevelStamping::No, + cssFiles, jsFiles + ); + } + else { + return std::make_unique( + filename, + append ? Append::Yes : Append::No, + timeStamp ? TimeStamping::Yes : TimeStamping::No, + dateStamp ? DateStamping::Yes : DateStamping::No, + categoryStamp ? CategoryStamping::Yes : CategoryStamping::No, + logLevelStamp ? LogLevelStamping::Yes : LogLevelStamping::No, + cssFiles, jsFiles, + ghoul::logging::levelFromString(logLevel) + ); + } } else if (type == valueTextLog) { - return std::make_unique( - filename, - append ? Append::Yes : Append::No, - timeStamp ? TimeStamping::Yes : TimeStamping::No, - dateStamp ? DateStamping::Yes : DateStamping::No, - categoryStamp ? CategoryStamping::Yes : CategoryStamping::No, - logLevelStamp ? LogLevelStamping::Yes : LogLevelStamping::No - ); + if (logLevel.empty()) { + return std::make_unique( + filename, + append ? Append::Yes : Append::No, + timeStamp ? TimeStamping::Yes : TimeStamping::No, + dateStamp ? DateStamping::Yes : DateStamping::No, + categoryStamp ? CategoryStamping::Yes : CategoryStamping::No, + logLevelStamp ? LogLevelStamping::Yes : LogLevelStamping::No + ); + } + else { + return std::make_unique( + filename, + append ? Append::Yes : Append::No, + timeStamp ? TimeStamping::Yes : TimeStamping::No, + dateStamp ? DateStamping::Yes : DateStamping::No, + categoryStamp ? CategoryStamping::Yes : CategoryStamping::No, + logLevelStamp ? LogLevelStamping::Yes : LogLevelStamping::No, + ghoul::logging::levelFromString(logLevel) + ); + } } else { throw ghoul::RuntimeError( diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 0aadcf9c3f..3759113f64 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -231,7 +231,7 @@ bool OpenSpaceEngine::create(int argc, char** argv, // configuration file, we will deinitialize this LogManager and reinitialize it later // with the correct LogLevel LogManager::initialize( - LogManager::LogLevel::Debug, + LogLevel::Debug, ghoul::logging::LogManager::ImmediateFlush::Yes ); LogMgr.addLog(std::make_unique()); @@ -792,7 +792,7 @@ void OpenSpaceEngine::configureLogging() { bool immediateFlush = false; configurationManager().getValue(KeyLogImmediateFlush, immediateFlush); - LogManager::LogLevel level = LogManager::levelFromString(logLevel); + LogLevel level = ghoul::logging::levelFromString(logLevel); LogManager::deinitialize(); using ImmediateFlush = ghoul::logging::LogManager::ImmediateFlush; LogManager::initialize( @@ -938,9 +938,9 @@ void OpenSpaceEngine::postSynchronizationPreDraw() { // Testing this every frame has minimal impact on the performance --- abock // Debug build: 1-2 us ; Release build: <= 1 us using ghoul::logging::LogManager; - int warningCounter = LogMgr.messageCounter(LogManager::LogLevel::Warning); - int errorCounter = LogMgr.messageCounter(LogManager::LogLevel::Error); - int fatalCounter = LogMgr.messageCounter(LogManager::LogLevel::Fatal); + int warningCounter = LogMgr.messageCounter(LogLevel::Warning); + int errorCounter = LogMgr.messageCounter(LogLevel::Error); + int fatalCounter = LogMgr.messageCounter(LogLevel::Fatal); if (warningCounter > 0) LWARNINGC("Logging", "Number of Warnings raised: " << warningCounter); diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index d6bf478772..85fd0b77a6 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -1695,7 +1695,7 @@ void RenderEngine::renderScreenLog() { if (alpha <= 0.0) break; - const std::string lvl = "(" + ghoul::logging::LogManager::stringFromLevel(e->level) + ")"; + const std::string lvl = "(" + ghoul::logging::stringFromLevel(e->level) + ")"; const std::string& message = e->message.substr(0, msg_length); nr += std::count(message.begin(), message.end(), '\n'); @@ -1708,13 +1708,13 @@ void RenderEngine::renderScreenLog() { e->category.length() > 20 ? "..." : ""); // Pad category with "..." if exceeds category_length glm::vec4 color = white; - if (e->level == ghoul::logging::LogManager::LogLevel::Debug) + if (e->level == ghoul::logging::LogLevel::Debug) color = green; - if (e->level == ghoul::logging::LogManager::LogLevel::Warning) + if (e->level == ghoul::logging::LogLevel::Warning) color = yellow; - if (e->level == ghoul::logging::LogManager::LogLevel::Error) + if (e->level == ghoul::logging::LogLevel::Error) color = red; - if (e->level == ghoul::logging::LogManager::LogLevel::Fatal) + if (e->level == ghoul::logging::LogLevel::Fatal) color = blue; // const float font_with_light = 5; diff --git a/src/scripting/scriptengine_lua.inl b/src/scripting/scriptengine_lua.inl index 1d32ba1455..7f6e8865df 100644 --- a/src/scripting/scriptengine_lua.inl +++ b/src/scripting/scriptengine_lua.inl @@ -26,7 +26,7 @@ namespace openspace { namespace luascriptfunctions { - int printInternal(ghoul::logging::LogManager::LogLevel level, lua_State* L) { + int printInternal(ghoul::logging::LogLevel level, lua_State* L) { using ghoul::lua::luaTypeToString; const std::string _loggerCat = "print"; @@ -67,7 +67,7 @@ namespace luascriptfunctions { * types, the type is printed instead */ int printDebug(lua_State* L) { - return printInternal(ghoul::logging::LogManager::LogLevel::Debug, L); + return printInternal(ghoul::logging::LogLevel::Debug, L); } /** @@ -78,7 +78,7 @@ namespace luascriptfunctions { * types, the type is printed instead */ int printInfo(lua_State* L) { - return printInternal(ghoul::logging::LogManager::LogLevel::Info, L); + return printInternal(ghoul::logging::LogLevel::Info, L); } /** @@ -89,7 +89,7 @@ namespace luascriptfunctions { * types, the type is printed instead */ int printWarning(lua_State* L) { - return printInternal(ghoul::logging::LogManager::LogLevel::Warning, L); + return printInternal(ghoul::logging::LogLevel::Warning, L); } /** @@ -100,7 +100,7 @@ namespace luascriptfunctions { * types, the type is printed instead */ int printError(lua_State* L) { - return printInternal(ghoul::logging::LogManager::LogLevel::Error, L); + return printInternal(ghoul::logging::LogLevel::Error, L); } /** @@ -111,7 +111,7 @@ namespace luascriptfunctions { * types, the type is printed instead */ int printFatal(lua_State* L) { - return printInternal(ghoul::logging::LogManager::LogLevel::Fatal, L); + return printInternal(ghoul::logging::LogLevel::Fatal, L); } /**