Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update logger to instead select verbose logging at compile time #62

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading