The problem with GetLevel()
is you’d need to add a static GetLevelStatic()
for accessing the logging singleton, which implies a mandatory indirection logInstance->GetLevel()
, if you want to do something like
#define URHO3D_LOGTRACEF(format, ...) GetLevelStatic() <= LOG_TRACE ? Write(LOG_TRACE, ToString(...)) : (void)0
@weitjong I am trying to add a URHO3D_MIN_LOG_LEVEL
input to the build system for logging, but can’t quite get it to work. Here are relevant parts of the diff
diff --git a/CMake/Modules/UrhoCommon.cmake b/CMake/Modules/UrhoCommon.cmake
index 4c1ac5989..7ec1aa0df 100644
--- a/CMake/Modules/UrhoCommon.cmake
+++ b/CMake/Modules/UrhoCommon.cmake
@@ -250,6 +250,8 @@ cmake_dependent_option (URHO3D_PACKAGING "Enable resources packaging support" FA
option (URHO3D_PROFILING "Enable profiling support" TRUE)
# Enable logging by default. If disabled, LOGXXXX macros become no-ops and the Log subsystem is not instantiated.
option (URHO3D_LOGGING "Enable logging support" TRUE)
+# Enable all log levels by default. Log levels lower than the min log level are no-ops. Can be set to any log level in the range [-1, 5] where any level >= 5 is no logging and any level <= 0 is 'all logging'. Log level -1 forces all log messages to be 'raw'.
+option (URHO3D_MIN_LOG_LEVEL "Set minimum log level from [-1, 5]" -1)
# Enable threading by default, except for Emscripten because its thread support is yet experimental
if (NOT WEB)
set (THREADING_DEFAULT TRUE)
@@ -391,6 +393,7 @@ if (URHO3D_CLANG_TOOLS)
URHO3D_IK
URHO3D_LOGGING
URHO3D_LUA
+ URHO3D_MIN_LOG_LEVEL
URHO3D_NAVIGATION
URHO3D_NETWORK
URHO3D_PHYSICS
@@ -440,6 +443,7 @@ foreach (OPT
URHO3D_IK
URHO3D_LOGGING
URHO3D_LUA
+ URHO3D_MIN_LOG_LEVEL
URHO3D_MINIDUMPS
URHO3D_NAVIGATION
URHO3D_NETWORK
diff --git a/script/.build-options b/script/.build-options
index 0b56fe363..b5059e962 100644
--- a/script/.build-options
+++ b/script/.build-options
@@ -37,6 +37,7 @@ URHO3D_HASH_DEBUG
URHO3D_PACKAGING
URHO3D_PROFILING
URHO3D_LOGGING
+URHO3D_MIN_LOG_LEVEL
URHO3D_THREADING
URHO3D_TESTING
URHO3D_TEST_TIMEOUT
diff --git a/script/.env-file b/script/.env-file
index b076050bb..1c6cf0fc3 100644
--- a/script/.env-file
+++ b/script/.env-file
@@ -120,6 +120,7 @@ URHO3D_LUAJIT
URHO3D_LUAJIT_AMALG
URHO3D_LUA_RAW_SCRIPT_LOADER
URHO3D_MACOSX_BUNDLE
+URHO3D_MIN_LOG_LEVEL
URHO3D_MINIDUMPS
URHO3D_MMX
URHO3D_NAVIGATION