From e0f745f0c95b2f892464ef794ea551084a067795 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 7 May 2022 23:20:46 +0200 Subject: [PATCH] Improve logging to include module name --- Makefile | 7 +++- source/function_patcher.cpp | 2 +- source/logger.h | 43 ------------------------ source/main.cpp | 2 +- source/{ => utils}/logger.c | 0 source/utils/logger.h | 66 +++++++++++++++++++++++++++++++++++++ 6 files changed, 74 insertions(+), 46 deletions(-) delete mode 100644 source/logger.h rename source/{ => utils}/logger.c (100%) create mode 100644 source/utils/logger.h diff --git a/Makefile b/Makefile index d13ffe0..0251a14 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ WUT_ROOT := $(DEVKITPRO)/wut #------------------------------------------------------------------------------- TARGET := FunctionPatcherModule BUILD := build -SOURCES := source +SOURCES := source source/utils DATA := data INCLUDES := source @@ -43,6 +43,11 @@ CXXFLAGS += -DDEBUG -g CFLAGS += -DDEBUG -g endif +ifeq ($(DEBUG),VERBOSE) +CXXFLAGS += -DDEBUG -DVERBOSE_DEBUG -g +CFLAGS += -DDEBUG -DVERBOSE_DEBUG -g +endif + LIBS := -lwums -lwut -lkernel #------------------------------------------------------------------------------- diff --git a/source/function_patcher.cpp b/source/function_patcher.cpp index d9b9261..f4adeca 100644 --- a/source/function_patcher.cpp +++ b/source/function_patcher.cpp @@ -1,6 +1,6 @@ #include "function_patcher.h" #include "CThread.h" -#include "logger.h" +#include "utils/logger.h" #include #include #include diff --git a/source/logger.h b/source/logger.h deleted file mode 100644 index 061d52e..0000000 --- a/source/logger.h +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef DEBUG - -#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) - -#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) \ - do { \ - WHBLogWritef("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \ - } 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 diff --git a/source/main.cpp b/source/main.cpp index 75ce468..6df20d5 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,7 +1,7 @@ -#include "logger.h" #include #include "function_patcher.h" +#include "utils/logger.h" WUMS_MODULE_EXPORT_NAME("homebrew_functionpatcher"); WUMS_MODULE_SKIP_INIT_FINI(); diff --git a/source/logger.c b/source/utils/logger.c similarity index 100% rename from source/logger.c rename to source/utils/logger.c diff --git a/source/utils/logger.h b/source/utils/logger.h new file mode 100644 index 0000000..d520bf4 --- /dev/null +++ b/source/utils/logger.h @@ -0,0 +1,66 @@ +#pragma once + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define LOG_APP_TYPE "M" +#define LOG_APP_NAME "function_patcher" + +#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) +#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__) + +#define LOG(LOG_FUNC, FMT, ARGS...) LOG_EX_DEFAULT(LOG_FUNC, "", "", FMT, ##ARGS) + +#define LOG_EX_DEFAULT(LOG_FUNC, LOG_LEVEL, LINE_END, FMT, ARGS...) LOG_EX(__FILENAME__, __FUNCTION__, __LINE__, LOG_FUNC, LOG_LEVEL, LINE_END, FMT, ##ARGS) + +#define LOG_EX(FILENAME, FUNCTION, LINE, LOG_FUNC, LOG_LEVEL, LINE_END, FMT, ARGS...) \ + do { \ + LOG_FUNC("[(%s)%18s][%23s]%30s@L%04d: " LOG_LEVEL "" FMT "" LINE_END, LOG_APP_TYPE, LOG_APP_NAME, FILENAME, FUNCTION, LINE, ##ARGS); \ + } while (0) + +#ifdef DEBUG + +#ifdef VERBOSE_DEBUG +#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) LOG(WHBLogPrintf, FMT, ##ARGS) +#define DEBUG_FUNCTION_LINE_VERBOSE_EX(FILENAME, FUNCTION, LINE, FMT, ARGS...) LOG_EX(FILENAME, FUNCTION, LINE, WHBLogPrintf, "", "", FMT, ##ARGS); +#else +#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0) +#define DEBUG_FUNCTION_LINE_VERBOSE_EX(FMT, ARGS...) while (0) +#endif + +#define DEBUG_FUNCTION_LINE(FMT, ARGS...) LOG(WHBLogPrintf, FMT, ##ARGS) + +#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) LOG(WHBLogWritef, FMT, ##ARGS) + +#define DEBUG_FUNCTION_LINE_ERR(FMT, ARGS...) LOG_EX_DEFAULT(WHBLogPrintf, "##ERROR## ", "", FMT, ##ARGS) + +#define DEBUG_FUNCTION_LINE_ERR_LAMBDA(FILENAME, FUNCTION, LINE, FMT, ARGS...) LOG_EX(FILENAME, FUNCTION, LINE, WHBLogPrintf, "##ERROR## ", "", FMT, ##ARGS); + +#else + +#define DEBUG_FUNCTION_LINE_VERBOSE_EX(FMT, ARGS...) while (0) + +#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) + +#define DEBUG_FUNCTION_LINE_ERR(FMT, ARGS...) LOG_EX_DEFAULT(OSReport, "##ERROR## ", "\n", FMT, ##ARGS) + +#define DEBUG_FUNCTION_LINE_ERR_LAMBDA(FILENAME, FUNCTION, LINE, FMT, ARGS...) LOG_EX(FILENAME, FUNCTION, LINE, OSReport, "##ERROR## ", "\n", FMT, ##ARGS); + +#endif + +void initLogging(); + +void deinitLogging(); + +#ifdef __cplusplus +} +#endif