Only do logging when built with make DEBUG=1, deinit logging properly

This commit is contained in:
Maschell 2022-01-23 22:16:51 +01:00
parent 91ad24571c
commit f8fb941b07
4 changed files with 60 additions and 10 deletions

View File

@ -31,7 +31,7 @@ INCLUDES := source
#-------------------------------------------------------------------------------
# options for code generation
#-------------------------------------------------------------------------------
CFLAGS := -g -Wall -O3 -ffunction-sections -fno-exceptions -fno-rtti\
CFLAGS := -Wall -O2 -ffunction-sections -fno-exceptions -fno-rtti\
$(MACHDEP)
CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__
@ -41,6 +41,11 @@ CXXFLAGS := $(CFLAGS) -std=c++20
ASFLAGS := -g $(ARCH)
LDFLAGS = -g $(ARCH) $(RPXSPECS) --entry=_start -Wl,-Map,$(notdir $*.map)
ifeq ($(DEBUG),1)
CXXFLAGS += -DDEBUG -g
CCFLAGS += -DDEBUG -g
endif
LIBS := -lwut -lz
#-------------------------------------------------------------------------------

View File

@ -3,9 +3,6 @@
#include <elfio/elfio.hpp>
#include <sysapp/launch.h>
#include <nn/act/client_cpp.h>
#include <whb/log_udp.h>
#include <whb/log_cafe.h>
#include <whb/log_module.h>
#include "fs/DirList.h"
#include "module/ModuleDataPersistence.h"
@ -18,10 +15,7 @@ extern "C" uint32_t textStart();
extern "C" void __fini();
int main(int argc, char **argv) {
if (!WHBLogModuleInit()) {
WHBLogCafeInit();
WHBLogUdpInit();
}
initLogging();
// We subtract 0x100 to be safe.
uint32_t textSectionStart = textStart() - 0x100;
@ -52,8 +46,6 @@ int main(int argc, char **argv) {
SetupRelocator();
WHBLogUdpDeinit();
nn::act::Initialize();
nn::act::SlotNo slot = nn::act::GetSlotNo();
nn::act::SlotNo defaultSlot = nn::act::GetDefaultAccount();
@ -65,6 +57,8 @@ int main(int argc, char **argv) {
_SYSLaunchMenuWithCheckingAccount(slot);
}
deinitLogging();
__fini();
return 0;
}

37
source/utils/logger.c Normal file
View File

@ -0,0 +1,37 @@
#ifdef DEBUG
#include <stdint.h>
#include <whb/log_udp.h>
#include <whb/log_cafe.h>
#include <whb/log_module.h>
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) {
WHBLogMffoduleDeinit();
moduleLogInit = false;
}
if (cafeLogInit) {
WHBLogCafeDeinit();
cafeLogInit = false;
}
if (udpLogInit) {
WHBLogUdpDeinit();
udpLogInit = false;
}
#endif // DEBUG
}

View File

@ -7,6 +7,8 @@
extern "C" {
#endif
#ifdef DEBUG
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
@ -18,6 +20,18 @@ extern "C" {
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0)
#else
#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