Do logging only when built with make DEBUG = 1

This commit is contained in:
Maschell 2022-01-30 17:35:12 +01:00
parent 2892967705
commit 81e6649a79
4 changed files with 66 additions and 21 deletions

View File

@ -22,14 +22,15 @@ WUMS_ROOT := $(DEVKITPRO)/wums
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
TARGET := regionfree TARGET := regionfree
BUILD := build BUILD := build
SOURCES := src SOURCES := src \
src/utils
DATA := data DATA := data
INCLUDES := src INCLUDES := src
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# options for code generation # options for code generation
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
CFLAGS := -g -Wall -O0 -ffunction-sections \ CFLAGS := -Wall -O0 -ffunction-sections \
$(MACHDEP) $(MACHDEP)
CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ -D__WUPS__ CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ -D__WUPS__
@ -39,6 +40,11 @@ CXXFLAGS := $(CFLAGS)
ASFLAGS := -g $(ARCH) ASFLAGS := -g $(ARCH)
LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) -T$(WUMS_ROOT)/share/libmappedmemory.ld $(WUPSSPECS) LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) -T$(WUMS_ROOT)/share/libmappedmemory.ld $(WUPSSPECS)
ifeq ($(DEBUG),1)
CXXFLAGS += -DDEBUG -g
CFLAGS += -DDEBUG -g
endif
LIBS := -lwut -lwups -lmappedmemory -lfreetype -lbz2 -lz -lpng LIBS := -lwut -lwups -lmappedmemory -lfreetype -lbz2 -lz -lpng
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------

View File

@ -1,5 +1,4 @@
#include <wups.h> #include <wups.h>
#include <whb/log_udp.h>
#include <nn/acp.h> #include <nn/acp.h>
#include <coreinit/title.h> #include <coreinit/title.h>
#include <coreinit/mcp.h> #include <coreinit/mcp.h>
@ -30,10 +29,6 @@ WUPS_USE_STORAGE("region_free_plugin");
bool getRealProductArea(MCPRegion *out); bool getRealProductArea(MCPRegion *out);
INITIALIZE_PLUGIN() {
WHBLogUdpInit();
}
DECL_FUNCTION(int32_t, ACPGetLaunchMetaXml, ACPMetaXml *metaxml) { DECL_FUNCTION(int32_t, ACPGetLaunchMetaXml, ACPMetaXml *metaxml) {
int result = real_ACPGetLaunchMetaXml(metaxml); int result = real_ACPGetLaunchMetaXml(metaxml);
if (metaxml != nullptr) { if (metaxml != nullptr) {
@ -42,7 +37,6 @@ DECL_FUNCTION(int32_t, ACPGetLaunchMetaXml, ACPMetaXml *metaxml) {
return result; return result;
} }
DECL_FUNCTION(int, UCReadSysConfig, int IOHandle, int count, struct UCSysConfig *settings) { DECL_FUNCTION(int, UCReadSysConfig, int IOHandle, int count, struct UCSysConfig *settings) {
int result = real_UCReadSysConfig(IOHandle, count, settings); int result = real_UCReadSysConfig(IOHandle, count, settings);
@ -72,6 +66,7 @@ ON_APPLICATION_ENDS() {
gCurrentLanguage = gDefaultLanguage; gCurrentLanguage = gDefaultLanguage;
gCurrentCountry = gDefaultCountry; gCurrentCountry = gDefaultCountry;
gCurrentProductArea = gDefaultProductArea; gCurrentProductArea = gDefaultProductArea;
deinitLogging();
} }
#define CAT_GENERAL_ROOT "root" #define CAT_GENERAL_ROOT "root"
@ -257,11 +252,10 @@ ON_FUNCTIONS_PATCHED() {
} }
WUPS_CloseStorage(); WUPS_CloseStorage();
} }
ON_APPLICATION_START() { ON_APPLICATION_START() {
WHBLogUdpInit(); initLogging();
WUPS_OpenStorage(); WUPS_OpenStorage();
@ -447,7 +441,6 @@ WUPS_CONFIG_CLOSED() {
WUPS_CloseStorage(); WUPS_CloseStorage();
} }
DECL_FUNCTION(int, MCP_GetSysProdSettings, int IOHandle, struct MCPSysProdSettings *settings) { DECL_FUNCTION(int, MCP_GetSysProdSettings, int IOHandle, struct MCPSysProdSettings *settings) {
int result = real_MCP_GetSysProdSettings(IOHandle, settings); int result = real_MCP_GetSysProdSettings(IOHandle, settings);

36
src/utils/logger.c Normal file
View File

@ -0,0 +1,36 @@
#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) {
WHBLogModuleDeinit();
moduleLogInit = false;
}
if (cafeLogInit) {
WHBLogCafeDeinit();
cafeLogInit = false;
}
if (udpLogInit) {
WHBLogUdpDeinit();
udpLogInit = false;
}
#endif // DEBUG
}

View File

@ -1,32 +1,42 @@
#ifndef __LOGGER_H_ #pragma once
#define __LOGGER_H_
#include <whb/log.h>
#include <string.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include <string.h> #ifdef DEBUG
#include <whb/log.h>
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) #define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__) #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
#define OSFATAL_FUNCTION_LINE(FMT, ARGS...)do { \ #define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
OSFatal_printf("[%s]%s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0)
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \ #define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0) } while (0)
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \ #define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ 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 #ifdef __cplusplus
} }
#endif #endif
#endif