From 733b2189be56c77d9f6bd44d6bf654254dd1f878 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sun, 30 Jan 2022 20:57:11 +0100 Subject: [PATCH] Only do logging when built with `make DEBUG=1` --- Makefile | 7 ++++++- src/main.cpp | 4 ++-- src/utils/logger.c | 36 ++++++++++++++++++++++++++++++++++++ src/utils/logger.h | 27 +++++++++++++++++++++------ 4 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 src/utils/logger.c diff --git a/Makefile b/Makefile index b44a984..9e18205 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ INCLUDES := src #------------------------------------------------------------------------------- # options for code generation #------------------------------------------------------------------------------- -CFLAGS := -g -Wall -O2 -ffunction-sections \ +CFLAGS := -Wall -O2 -ffunction-sections \ $(MACHDEP) CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ -D__WUPS__ @@ -38,6 +38,11 @@ CXXFLAGS := $(CFLAGS) ASFLAGS := -g $(ARCH) LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) $(WUPSSPECS) +ifeq ($(DEBUG),1) +CXXFLAGS += -DDEBUG -g +CFLAGS += -DDEBUG -g +endif + LIBS := -lwups -lwut -liosuhax #------------------------------------------------------------------------------- diff --git a/src/main.cpp b/src/main.cpp index ad4f1b7..9044e63 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,8 +33,7 @@ ON_APPLICATION_START() { nn::ac::Initialize(); nn::ac::ConnectAsync(); nn::ac::GetAssignedAddress(&hostIpAddress); - - WHBLogUdpInit(); + initLogging(); //!******************************************************************* //! Initialize FS * @@ -111,5 +110,6 @@ ON_APPLICATION_REQUESTS_EXIT() { } UnmountVirtualPaths(); + deinitLogging(); } diff --git a/src/utils/logger.c b/src/utils/logger.c new file mode 100644 index 0000000..0411db7 --- /dev/null +++ b/src/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/src/utils/logger.h b/src/utils/logger.h index dc67c5f..6ff5ae2 100644 --- a/src/utils/logger.h +++ b/src/utils/logger.h @@ -1,18 +1,18 @@ #pragma once +#include +#include + #ifdef __cplusplus extern "C" { #endif -#include -#include +#ifdef DEBUG #define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__) -#define OSFATAL_FUNCTION_LINE(FMT, ARGS...)do { \ - OSFatal_printf("[%s]%s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ - } while (0) +#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); \ @@ -20,8 +20,23 @@ extern "C" { #define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \ WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ - } while (0); + } while (0) + +#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 +