all repos — mgba @ 33a9fad209a3f6ef08f34b3f179746960f807f6f

mGBA Game Boy Advance Emulator

GUI: Add back logging
Jeffrey Pfau jeffrey@endrift.com
Mon, 08 Aug 2016 20:57:44 -0700
commit

33a9fad209a3f6ef08f34b3f179746960f807f6f

parent

c597d6dcfaf7dd0415aa60b1bd5c9b291c6c5e02

2 files changed, 46 insertions(+), 0 deletions(-)

jump to
M CHANGESCHANGES

@@ -42,6 +42,7 @@ - Qt: Make audio channel/video layer options shortcut mappable

- GBA Memory: Optimize stalling behavior - 3DS: Attempt to use Core 2 for threads - GUI: Screenshot dimensions are now passed through + - GUI: Add back logging 0.4.1: (2016-07-11) Bugfixes:
M src/feature/gui/gui-runner.csrc/feature/gui/gui-runner.c

@@ -48,6 +48,20 @@ RUNNER_STATE_8 = 0x80000,

RUNNER_STATE_9 = 0x90000, }; +static void _log(struct mLogger*, int category, enum mLogLevel level, const char* format, va_list args); + +static struct mGUILogger { + struct mLogger d; + struct VFile* vf; + int logLevel; +} logger = { + .d = { + .log = _log + }, + .vf = NULL, + .logLevel = 0 +}; + static void _drawBackground(struct GUIBackground* background, void* context) { UNUSED(context); struct mGUIBackground* gbaBackground = (struct mGUIBackground*) background;

@@ -122,6 +136,12 @@ runner->fps = 0;

runner->lastFpsCheck = 0; runner->totalDelta = 0; CircleBufferInit(&runner->fpsBuffer, FPS_BUFFER_SIZE * sizeof(uint32_t)); + + char path[PATH_MAX]; + mCoreConfigDirectory(path, PATH_MAX); + strncat(path, PATH_SEP "log", PATH_MAX - strlen(path)); + logger.vf = VFileOpen(path, O_CREAT | O_WRONLY | O_APPEND); + mLogSetDefaultLogger(&logger.d); } void mGUIDeinit(struct mGUIRunner* runner) {

@@ -129,6 +149,29 @@ if (runner->teardown) {

runner->teardown(runner); } CircleBufferDeinit(&runner->fpsBuffer); + if (logger.vf) { + logger.vf->close(logger.vf); + logger.vf = NULL; + } +} + +static void _log(struct mLogger* logger, int category, enum mLogLevel level, const char* format, va_list args) { + struct mGUILogger* guiLogger = (struct mGUILogger*) logger; + if (!guiLogger->vf) { + return; + } + if (!(guiLogger->logLevel & level)) { + return; + } + + char log[256] = {0}; + vsnprintf(log, sizeof(log) - 1, format, args); + char log2[256] = {0}; + size_t len = snprintf(log2, sizeof(log2) - 1, "%s: %s\n", mLogCategoryName(category), log); + if (len >= sizeof(log2)) { + len = sizeof(log2) - 1; + } + guiLogger->vf->write(guiLogger->vf, log2, len); } void mGUIRun(struct mGUIRunner* runner, const char* path) {

@@ -238,6 +281,8 @@ // TODO: Do we need to load more defaults?

mCoreConfigSetDefaultIntValue(&runner->core->config, "volume", 0x100); mCoreConfigSetDefaultValue(&runner->core->config, "idleOptimization", "detect"); mCoreLoadConfig(runner->core); + logger.logLevel = runner->core->opts.logLevel; + mCoreAutoloadSave(runner->core); if (runner->setup) { runner->setup(runner);