Game

Debug Utilities

Using the DebugManager and logging macros.

Overview

Nevo Engine provides a thread-safe logging system via the DebugManager. It supports multiple log levels, console output, and automatic file rotation.

Initialization

The DebugManager is typically initialized in your main.cpp.

Public::Debug::DebugManager::getInstance().Initialize("game.log");
Public::Debug::DebugManager::getInstance().EnableConsoleOutput(true);
Public::Debug::DebugManager::getInstance().SetMinLogLevel(Public::Debug::DebugManager::LogLevel::Verbose);

Logging Macros

It is recommended to use the provided macros for logging, as they handle the singleton access for you.

  • LOG_VERBOSE("message"): Detailed debug info for internal tracking.
  • LOG_INFO("message"): General informational messages about engine state.
  • LOG_ASSERT("message"): High-visibility notification for developers. Use this for events that are not errors but require immediate attention (e.g., specific flag triggers or logic checkpoints).
  • LOG_WARNING("message"): Indicates potential issues that don't stop execution but should be investigated.
  • LOG_ERROR("message"): Significant errors that allow the application to continue but indicate a failure in a specific task.
  • LOG_CRITICAL("message"): Severe, unrecoverable errors that usually precede an application shutdown or crash.
LOG_VERBOSE("Updating system iteration...");
LOG_INFO("Scene 'Level1' loaded successfully.");
LOG_ASSERT("Developer Mode enabled via command line flag.");
LOG_WARNING("Texture 'missing_tex' not found, using fallback.");
LOG_ERROR("Failed to initialize Audio Device.");
LOG_CRITICAL("FATAL: Memory allocation failed during buffer upload!");

Crash Handling

The DebugManager includes capabilities to hook into system signals or exception filters to log critical information before a crash occurs. This ensures that the reason for a failure is captured in your log files even if the application terminates abruptly.

Integration Example

In your main.cpp, you can set up platform-specific handlers that pipe information into the DebugManager.

#ifdef _WIN32
#include <Windows.h>
LONG WINAPI UnhandledExceptionHandler(EXCEPTION_POINTERS* exceptionInfo) {
    Public::Debug::DebugManager::getInstance().UnhandledExceptionHandler("System Exception Caught");
    return EXCEPTION_CONTINUE_SEARCH;
}
#else
#include <csignal>
void SignalHandler(int signal) {
    LOG_CRITICAL("Caught signal: " + std::string(strsignal(signal)));
    std::_Exit(EXIT_FAILURE);
}
#endif

int main() {
    // 1. Setup platform handlers
#ifdef _WIN32
    SetUnhandledExceptionFilter(UnhandledExceptionHandler);
#else
    struct sigaction sa;
    sa.sa_handler = SignalHandler;
    sigemptyset(&sa.sa_mask);
    sigaction(SIGSEGV, &sa, nullptr);
    sigaction(SIGABRT, &sa, nullptr);
#endif

    // 2. Initialize DebugManager
    Public::Debug::DebugManager::getInstance().Initialize("game.log");
    
    // ... rest of game initialization ...
}