diff --git a/source/main.cpp b/source/main.cpp index 28d51d1..606a036 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -88,19 +88,9 @@ bool writeFileContent(const std::string &path, const std::string &content) { extern "C" void __fini(); -#ifdef DEBUG -bool module_log = false; -bool udp_log = false; -bool cafe_log = false; -#endif // DEBUG int main(int argc, char **argv) { -#ifdef DEBUG - if (!(module_log = WHBLogModuleInit())) { - cafe_log = WHBLogCafeInit(); - udp_log = WHBLogUdpInit(); - } -#endif // DEBUG + initLogging(); if (IOS_Open((char *) ("/dev/iosuhax"), static_cast(0)) >= 0) { auto checkTiramisuHBL = fopen("fs:/vol/external01/wiiu/environments/tiramisu/modules/setup/50_hbl_installer.rpx", "r"); @@ -238,11 +228,7 @@ int main(int argc, char **argv) { } ProcUIShutdown(); -#ifdef DEBUG - if (module_log) { WHBLogModuleDeinit(); } - if (udp_log) { WHBLogUdpDeinit(); } - if (cafe_log) { WHBLogCafeDeinit(); } -#endif // DEBUG + deinitLogging(); __fini(); return 0; } diff --git a/source/utils/logger.c b/source/utils/logger.c new file mode 100644 index 0000000..0411db7 --- /dev/null +++ b/source/utils/logger.c @@ -0,0 +1,36 @@ +#ifdef DEBUG +#include +#include +#include +#include + +uint32_t moduleLogInit = false; +uint32_t cafeLogInit = false; +uint32_t udpLogInit = false; +#endif // DEBUG + +void initLogging() { +#ifdef DEBUG + if (!(moduleLogInit = WHBLogModuleInit())) { + cafeLogInit = WHBLogCafeInit(); + udpLogInit = WHBLogUdpInit(); + } +#endif // DEBUG +} + +void deinitLogging() { +#ifdef DEBUG + if (moduleLogInit) { + WHBLogModuleDeinit(); + moduleLogInit = false; + } + if (cafeLogInit) { + WHBLogCafeDeinit(); + cafeLogInit = false; + } + if (udpLogInit) { + WHBLogUdpDeinit(); + udpLogInit = false; + } +#endif // DEBUG +} \ No newline at end of file diff --git a/source/utils/logger.h b/source/utils/logger.h index 014f6f7..6ff5ae2 100644 --- a/source/utils/logger.h +++ b/source/utils/logger.h @@ -12,6 +12,8 @@ extern "C" { #define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__) +#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0) + #define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \ WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ } while (0) @@ -22,12 +24,18 @@ extern "C" { #else +#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0) + #define DEBUG_FUNCTION_LINE(FMT, ARGS...) while (0) #define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0) - + #endif +void initLogging(); + +void deinitLogging(); + #ifdef __cplusplus } #endif