diff options
| author | Malkierian <malkierian@gmail.com> | 2025-11-03 18:54:01 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-03 18:54:01 -0700 |
| commit | cf275b1a6c25a79a96a28cf5d73421d80ee4d15a (patch) | |
| tree | c2b5f7dff876d7ab3302b16a48c765143f9e7995 | |
| parent | 0014f406762bcbff75b5c69a09a0496050078498 (diff) | |
Implement logger changes (#5914)
* Implement logger changes, and make default log level dynamic based on debug/release.
* Bump LUS.
* typo
Co-authored-by: Eblo <7004497+Eblo@users.noreply.github.com>
---------
Co-authored-by: Eblo <7004497+Eblo@users.noreply.github.com>
| -rw-r--r-- | CMake/logging.cmake | 20 | ||||
| -rw-r--r-- | CMakeLists.txt | 1 | ||||
| m--------- | libultraship | 0 | ||||
| -rw-r--r-- | soh/include/functions.h | 4 | ||||
| -rw-r--r-- | soh/soh/Enhancements/randomizer/static_data.cpp | 4 | ||||
| -rw-r--r-- | soh/soh/OTRGlobals.cpp | 8 |
6 files changed, 32 insertions, 5 deletions
diff --git a/CMake/logging.cmake b/CMake/logging.cmake new file mode 100644 index 000000000..268ad27b4 --- /dev/null +++ b/CMake/logging.cmake @@ -0,0 +1,20 @@ +set(SPDLOG_LEVEL_TRACE 0) +set(SPDLOG_LEVEL_DEBUG 1) +set(SPDLOG_LEVEL_INFO 2) +set(SPDLOG_LEVEL_WARN 3) +set(SPDLOG_LEVEL_ERROR 4) +set(SPDLOG_LEVEL_CRITICAL 5) +set(SPDLOG_LEVEL_OFF 6) +set(LOG_LEVELS "SPDLOG_LEVEL_TRACE;SPDLOG_LEVEL_DEBUG;SPDLOG_LEVEL_INFO;SPDLOG_LEVEL_WARN;SPDLOG_LEVEL_ERROR;SPDLOG_LEVEL_CRITICAL;SPDLOG_LEVEL_OFF") +set(LOG_LEVEL SPDLOG_LEVEL_TRACE CACHE STRING "The spdlog level that prints will be logged out. Overridden to SPDLOG_LEVEL_ERROR on Release builds.") +set_property(CACHE LOG_LEVEL PROPERTY STRINGS ${LOG_LEVELS}) +if(NOT LOG_LEVEL IN_LIST LOG_LEVELS) + message(FATAL_ERROR "LOG_LEVEL must be one of ${LOG_LEVELS}") +endif() +set(SPDLOG_ACTIVE_LEVEL ${${LOG_LEVEL}}) +set(LOG_LEVEL_GAME_PRINTS ${SPDLOG_LEVEL_OFF}) + +add_compile_definitions( + LOG_LEVEL_GAME_PRINTS=${LOG_LEVEL_GAME_PRINTS} + SPDLOG_ACTIVE_LEVEL=${SPDLOG_ACTIVE_LEVEL} +)
\ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 64008668b..7ed0b6bc8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment ve project(Ship VERSION 9.1.0 LANGUAGES C CXX) include(CMake/soh-cvars.cmake) include(CMake/lus-cvars.cmake) +include(CMake/logging.cmake) option(SUPPRESS_WARNINGS "Suppress warnings in LUS and src (decomp)" ON) if(SUPPRESS_WARNINGS) diff --git a/libultraship b/libultraship -Subproject 5f4be9b6f5f74917c303ab8b66a0b2f4ef91613 +Subproject 17a0b7939bd05f5e617cef89457ca43774fc9a9 diff --git a/soh/include/functions.h b/soh/include/functions.h index 9d96a3c8b..11dbf8c81 100644 --- a/soh/include/functions.h +++ b/soh/include/functions.h @@ -13,8 +13,8 @@ extern "C" #include <libultraship/log/luslog.h> #include <soh/Enhancements/item-tables/ItemTableTypes.h> -#if defined(INCLUDE_GAME_PRINTF) && defined(_DEBUG) -#define osSyncPrintf(fmt, ...) lusprintf(__FILE__, __LINE__, 0, fmt, ##__VA_ARGS__) +#if (LOG_LEVEL_GAME_PRINTS >= SPDLOG_ACTIVE_LEVEL) && !(LOG_LEVEL_GAME_PRINTS >= 6) +#define osSyncPrintf(...) lusprintf(__FILE__, __LINE__, LOG_LEVEL_GAME_PRINTS , __VA_ARGS__) #else #define osSyncPrintf(fmt, ...) osSyncPrintfUnused(fmt, ##__VA_ARGS__) #endif diff --git a/soh/soh/Enhancements/randomizer/static_data.cpp b/soh/soh/Enhancements/randomizer/static_data.cpp index 1becef894..ba2dff847 100644 --- a/soh/soh/Enhancements/randomizer/static_data.cpp +++ b/soh/soh/Enhancements/randomizer/static_data.cpp @@ -225,7 +225,7 @@ StaticData::PopulateTranslationMap(std::unordered_map<uint32_t, CustomMessage> i if (output.contains(string)) { if (output[string] != key) { // RANDOTODO should this cause an error of some kind? - SPDLOG_DEBUG("\tREPEATED STRING IN " + message.GetEnglish(MF_CLEAN) + "\n\n"); + SPDLOG_DEBUG("REPEATED STRING IN " + message.GetEnglish(MF_CLEAN)); } } else { output[string] = key; @@ -244,7 +244,7 @@ StaticData::PopulateTranslationMap(std::unordered_map<uint32_t, RandomizerHintTe if (output.contains(string)) { if (output[string] != key) { // RANDOTODO should this cause an error of some kind? - SPDLOG_DEBUG("\tREPEATED STRING WITH " + string + "\n\n"); + SPDLOG_DEBUG("REPEATED STRING WITH " + string); } } else { output[string] = key; diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index cbcc926d9..222c7ad8c 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -12,6 +12,7 @@ #include <fast/resource/type/DisplayList.h> #include <ship/window/Window.h> #include <soh/GameVersions.h> +#include <spdlog/sinks/rotating_file_sink.h> #include "Enhancements/gameconsole.h" #ifdef _WIN32 @@ -319,8 +320,13 @@ void OTRGlobals::Initialize() { context->InitCrashHandler(); context->InitConsole(); +#if (_DEBUG) + int defaultLogLevel = 0; +#else + int defaultLogLevel = 2; +#endif Ship::Context::GetInstance()->GetLogger()->set_level( - (spdlog::level::level_enum)CVarGetInteger(CVAR_DEVELOPER_TOOLS("LogLevel"), 1)); + (spdlog::level::level_enum)CVarGetInteger(CVAR_DEVELOPER_TOOLS("LogLevel"), defaultLogLevel)); Ship::Context::GetInstance()->GetLogger()->set_pattern("[%H:%M:%S.%e] [%s:%#] [%l] %v"); auto sohInputEditorWindow = |
