Improve logging

This commit is contained in:
Maschell 2022-09-03 23:29:22 +02:00
parent b6ff1dc16b
commit c286c94701
2 changed files with 30 additions and 6 deletions

23
source/logger.h Normal file
View File

@ -0,0 +1,23 @@
#pragma once
#include <coreinit/debug.h>
#include <cstring>
#define __FILENAME__ ({ \
const char *__filename = __FILE__; \
const char *__pos = strrchr(__filename, '/'); \
if (!__pos) __pos = strrchr(__filename, '\\'); \
__pos ? __pos + 1 : __filename; \
})
#define LOG_APP_TYPE "L"
#define LOG_APP_NAME "libsdutils"
#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)
#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 DEBUG_FUNCTION_LINE_ERR(FMT, ARGS...) LOG_EX_DEFAULT(OSReport, "##ERROR## ", "\n", FMT, ##ARGS)
#define DEBUG_FUNCTION_LINE_WARN(FMT, ARGS...) LOG_EX_DEFAULT(OSReport, "##WARNING## ", "\n", FMT, ##ARGS)

View File

@ -1,3 +1,4 @@
#include "logger.h"
#include "sdutils/sdutils.h" #include "sdutils/sdutils.h"
#include <coreinit/debug.h> #include <coreinit/debug.h>
#include <coreinit/dynload.h> #include <coreinit/dynload.h>
@ -17,12 +18,12 @@ static SDUtilsVersion sSDUtilsVersion = SD_UTILS_MODULE_VERSION_ERROR;
SDUtilsStatus SDUtils_InitLibrary() { SDUtilsStatus SDUtils_InitLibrary() {
if (OSDynLoad_Acquire("homebrew_sdhotswap", &sModuleHandle) != OS_DYNLOAD_OK) { if (OSDynLoad_Acquire("homebrew_sdhotswap", &sModuleHandle) != OS_DYNLOAD_OK) {
OSReport("SDUtils_Init: OSDynLoad_Acquire failed.\n"); DEBUG_FUNCTION_LINE_ERR("SDUtils_Init: OSDynLoad_Acquire failed.");
return SDUTILS_RESULT_MODULE_NOT_FOUND; return SDUTILS_RESULT_MODULE_NOT_FOUND;
} }
if (OSDynLoad_FindExport(sModuleHandle, FALSE, "SDUtilsGetVersion", (void **) &sSDUtilsGetVersion) != OS_DYNLOAD_OK) { if (OSDynLoad_FindExport(sModuleHandle, FALSE, "SDUtilsGetVersion", (void **) &sSDUtilsGetVersion) != OS_DYNLOAD_OK) {
OSReport("SDUtils_Init: SDUtilsGetVersion failed.\n"); DEBUG_FUNCTION_LINE_ERR("SDUtils_Init: SDUtilsGetVersion failed.");
return SDUTILS_RESULT_MODULE_MISSING_EXPORT; return SDUTILS_RESULT_MODULE_MISSING_EXPORT;
} }
@ -32,22 +33,22 @@ SDUtilsStatus SDUtils_InitLibrary() {
} }
if (OSDynLoad_FindExport(sModuleHandle, FALSE, "SDUtilsAddAttachHandler", (void **) &sSDUtilsAddAttachHandler) != OS_DYNLOAD_OK) { if (OSDynLoad_FindExport(sModuleHandle, FALSE, "SDUtilsAddAttachHandler", (void **) &sSDUtilsAddAttachHandler) != OS_DYNLOAD_OK) {
OSReport("SDUtils_Init: SDUtilsAddAttachHandler failed.\n"); DEBUG_FUNCTION_LINE_ERR("SDUtils_Init: SDUtilsAddAttachHandler failed.");
return SDUTILS_RESULT_MODULE_MISSING_EXPORT; return SDUTILS_RESULT_MODULE_MISSING_EXPORT;
} }
if (OSDynLoad_FindExport(sModuleHandle, FALSE, "SDUtilsRemoveAttachHandler", (void **) &sSDUtilsRemoveAttachHandler) != OS_DYNLOAD_OK) { if (OSDynLoad_FindExport(sModuleHandle, FALSE, "SDUtilsRemoveAttachHandler", (void **) &sSDUtilsRemoveAttachHandler) != OS_DYNLOAD_OK) {
OSReport("SDUtils_Init: SDUtilsRemoveAttachHandler failed.\n"); DEBUG_FUNCTION_LINE_ERR("SDUtils_Init: SDUtilsRemoveAttachHandler failed.");
return SDUTILS_RESULT_MODULE_MISSING_EXPORT; return SDUTILS_RESULT_MODULE_MISSING_EXPORT;
} }
if (OSDynLoad_FindExport(sModuleHandle, FALSE, "SDUtilsAddCleanUpHandlesHandler", (void **) &sSDUtilsAddCleanUpHandlesHandler) != OS_DYNLOAD_OK) { if (OSDynLoad_FindExport(sModuleHandle, FALSE, "SDUtilsAddCleanUpHandlesHandler", (void **) &sSDUtilsAddCleanUpHandlesHandler) != OS_DYNLOAD_OK) {
OSReport("SDUtils_Init: SDUtilsAddCleanUpHandlesHandler failed.\n"); DEBUG_FUNCTION_LINE_ERR("SDUtils_Init: SDUtilsAddCleanUpHandlesHandler failed.");
return SDUTILS_RESULT_MODULE_MISSING_EXPORT; return SDUTILS_RESULT_MODULE_MISSING_EXPORT;
} }
if (OSDynLoad_FindExport(sModuleHandle, FALSE, "SDUtilsRemoveCleanUpHandlesHandler", (void **) &sSDUtilsRemoveCleanUpHandlesHandler) != OS_DYNLOAD_OK) { if (OSDynLoad_FindExport(sModuleHandle, FALSE, "SDUtilsRemoveCleanUpHandlesHandler", (void **) &sSDUtilsRemoveCleanUpHandlesHandler) != OS_DYNLOAD_OK) {
OSReport("SDUtils_Init: SDUtilsRemoveCleanUpHandlesHandler failed.\n"); DEBUG_FUNCTION_LINE_ERR("SDUtils_Init: SDUtilsRemoveCleanUpHandlesHandler failed.");
return SDUTILS_RESULT_MODULE_MISSING_EXPORT; return SDUTILS_RESULT_MODULE_MISSING_EXPORT;
} }