Move logging into a separate file

This commit is contained in:
Maschell 2022-01-30 13:53:29 +01:00
parent a9616036f9
commit 4e29e33931
4 changed files with 47 additions and 22 deletions

View File

@ -49,7 +49,7 @@ LDFLAGS := -nostartfiles -Wl,--gc-sections,--allow-multiple-definition
ifeq ($(DEBUG),1)
CXXFLAGS += -DDEBUG -g
CCFLAGS += -DDEBUG -g
CFLAGS += -DDEBUG -g
endif
#---------------------------------------------------------------------------------

View File

@ -30,10 +30,6 @@
#include "module/ModuleDataFactory.h"
#include "common/module_defines.h"
#include <whb/log.h>
#include <whb/log_udp.h>
#include <whb/log_cafe.h>
#include <whb/log_module.h>
#include <utils/StringTools.h>
#include "kernel.h"
@ -71,12 +67,6 @@ bool CheckRunning() {
extern "C" void __init_wut();
extern "C" void __fini_wut();
#ifdef DEBUG
bool module_log = false;
bool udp_log = false;
bool cafe_log = false;
#endif // DEBUG
extern "C" int _start(int argc, char **argv) __attribute__ ((section (".start_code")));
extern "C" int _start(int argc, char **argv) {
doKernelSetup();
@ -90,21 +80,12 @@ extern "C" int _start(int argc, char **argv) {
auto heap = (MEMExpHeap *) mem2_heap_handle;
MEMExpHeapBlock *memory_start = heap->usedList.tail;
#ifdef DEBUG
if (!(module_log = WHBLogModuleInit())) {
cafe_log = WHBLogCafeInit();
udp_log = WHBLogUdpInit();
}
#endif // DEBUG
initLogging();
DEBUG_FUNCTION_LINE("Hello from CustomRPXloader");
uint32_t entrypoint = do_start(argc, argv);
#ifdef DEBUG
if (module_log) { WHBLogModuleDeinit(); }
if (udp_log) { WHBLogUdpDeinit(); }
if (cafe_log) { WHBLogCafeDeinit(); }
#endif // DEBUG
deinitLogging();
// free leaked memory
if (memory_start) {

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

@ -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