Skip to content

Commit

Permalink
Update logger to instead select verbose logging at compile time
Browse files Browse the repository at this point in the history
  • Loading branch information
Rinzii committed Nov 21, 2023
1 parent 3d71330 commit d2a0ad2
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ if(PROJECT_NAME STREQUAL CMAKE_PROJECT_NAME)
endif()

option(GENESIS_ENABLE_EDITOR "Set the runtime to instead build the editor instead of the default" ON)
option(GENESIS_ENABLE_VERBOSE_LOGGING "Enable verbose logging" OFF)
option(GENESIS_BUILD_RUNTIME "Build the genesis runtime (else only library)" ON)
option(GENESIS_BUILD_GAME "Build the genesis game" ON)
option(GENESIS_BUILD_SHADERS "Build the genesis shaders" ON)
Expand Down
9 changes: 9 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@
"GENESIS_PCH": "OFF"
}
},
{
"name": "ninja-verbose-logging",
"description": "Build configuration using Ninja Multi-config / verbose logging enabled",
"inherits": "default",
"binaryDir": "${sourceDir}/out/verbose",
"cacheVariables": {
"GENESIS_ENABLE_VERBOSE_LOGGING": "ON"
}
},
{
"name": "vs19",
"description": "Build configuration using Visual Studio 16 (2019)",
Expand Down
3 changes: 0 additions & 3 deletions editor/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ int main()
{
// TODO: Make this be set by a config file.
auto config = gen::logger::Config{};
#ifdef GEN_DEBUG
config.verbose = true;
#endif

// Required to initialize the logger for the application. This must also stay outside the try/catch block.
auto logger = gen::logger::Instance{logFile, config};
Expand Down
4 changes: 4 additions & 0 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ target_compile_definitions(genesis
$<$<CONFIG:Release>:GEN_NDEBUG>
)

if(GENESIS_ENABLE_VERBOSE_LOGGING)
target_compile_definitions(genesis PUBLIC GEN_VERBOSE_LOGGING)
endif()

if (GENESIS_ENABLE_SIMD)
# This create an internal definition that allows our project to check if it can use simd.
# If the code decides it can then GEN_SIMD will be defined along with a bunch of other SIMD related defines.
Expand Down
7 changes: 1 addition & 6 deletions engine/include/gen/logger/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace gen::logger
/// file: file name
/// line: line number
///
static constexpr std::string_view verbose_format_v{"[{level}][T{thread}] [{category}] {message} [{timestamp}] [F: {func}] [{file}:{line}]"};
static constexpr std::string_view verbose_format_v{"[{level}][T{thread}] [{category}] {message} [{timestamp}] [F:{func}] [{file}:{line}]"};

static constexpr std::size_t format_size_v{128};

Expand Down Expand Up @@ -83,10 +83,5 @@ namespace gen::logger
/// \brief Timestamp mode.
///
Timestamp timestamp{Timestamp::eLocal};

///
/// \brief Whether to print verbose logging information.
///
bool verbose{false};
};
} // namespace gen::logger
13 changes: 3 additions & 10 deletions engine/src/logger/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,16 +258,9 @@ namespace gen::logger
return all_v;
}();

if (config.verbose)
{
// verbose logging is enabled, override the format
config.format = Config::verbose_format_v;
}
else
{
// verbose logging is disabled, set the format back to default.
config.format = Config::default_format_v;
}
#ifdef GEN_VERBOSE_LOGGING
config.format = Config::verbose_format_v;
#endif

auto const data = Formatter::Data{.format = config.format, .timestamp = config.timestamp};
// cache this for later use
Expand Down

0 comments on commit d2a0ad2

Please sign in to comment.