libwhb: Add option to log to the LoggingModule

This commit is contained in:
Maschell 2021-11-06 17:09:48 +01:00 committed by fincs
parent 563b9d6c89
commit ce2cd4e843
2 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,24 @@
#pragma once
#include <wut.h>
/**
* \defgroup whb_log_module Log using the LoggingModule.
* \ingroup whb
* @{
*/
#ifdef __cplusplus
extern "C" {
#endif
BOOL
WHBLogModuleInit();
BOOL
WHBLogModuleDeinit();
#ifdef __cplusplus
}
#endif
/** @} */

View File

@ -0,0 +1,37 @@
#include <coreinit/dynload.h>
#include <coreinit/debug.h>
#include <whb/log.h>
#include <string.h>
static OSDynLoad_Module sModuleHandle = NULL;
static void (*sWUMSLogWrite)(const char *, size_t) = NULL;
static void
moduleLogHandler(const char *msg)
{
if(sWUMSLogWrite != NULL) {
sWUMSLogWrite(msg, strlen(msg));
}
}
BOOL
WHBLogModuleInit()
{
if (OSDynLoad_Acquire("homebrew_logging", &sModuleHandle) != OS_DYNLOAD_OK) {
OSReport("WHBLogModuleInit: OSDynLoad_Acquire failed.\n");
return false;
}
if (OSDynLoad_FindExport(sModuleHandle, FALSE, "WUMSLogWrite", (void**) &sWUMSLogWrite) != OS_DYNLOAD_OK) {
OSReport("WHBLogModuleInit: OSDynLoad_FindExport failed.\n");
return false;
}
return WHBAddLogHandler(moduleLogHandler);
}
BOOL
WHBLogModuleDeinit()
{
return WHBRemoveLogHandler(moduleLogHandler);
}