src/platform/python/log.c (view raw)
1/* Copyright (c) 2013-2016 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#include <mgba/core/log.h>
7
8struct mLoggerPy {
9 struct mLogger d;
10 void* pyobj;
11};
12
13void _pyLog(void* logger, int category, enum mLogLevel level, const char* message);
14
15static void _pyLogShim(struct mLogger* logger, int category, enum mLogLevel level, const char* format, va_list args) {
16 struct mLoggerPy* pylogger = (struct mLoggerPy*) logger;
17 char message[256] = {0};
18 vsnprintf(message, sizeof(message) - 1, format, args);
19 _pyLog(pylogger, category, level, message);
20}
21
22struct mLogger* mLoggerPythonCreate(void* pyobj) {
23 struct mLoggerPy* logger = malloc(sizeof(*logger));
24 logger->d.log = _pyLogShim;
25 logger->d.filter = NULL;
26 logger->pyobj = pyobj;
27 return &logger->d;
28}