all repos — mgba @ 1dff579ad4a6e5ccb1152b8cddd74975b970b0b3

mGBA Game Boy Advance Emulator

src/platform/python/mgba/log.py (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/.
 6from ._pylib import ffi, lib
 7
 8@ffi.def_extern()
 9def _pyLog(logger, category, level, message):
10	l = ffi.cast("struct mLoggerPy*", logger)
11	ffi.from_handle(l.pyobj).log(category, level, ffi.string(message).decode('UTF-8'))
12
13def installDefault(logger):
14	lib.mLogSetDefaultLogger(logger._native)
15
16class Logger(object):
17	FATAL = lib.mLOG_FATAL
18	DEBUG = lib.mLOG_DEBUG
19	INFO = lib.mLOG_INFO
20	WARN = lib.mLOG_WARN
21	ERROR = lib.mLOG_ERROR
22	STUB = lib.mLOG_STUB
23	GAME_ERROR = lib.mLOG_GAME_ERROR
24
25	def __init__(self):
26		self._handle = ffi.new_handle(self)
27		self._native = ffi.gc(lib.mLoggerPythonCreate(self._handle), lib.free)
28
29	@staticmethod
30	def categoryName(category):
31		return ffi.string(lib.mLogCategoryName(category)).decode('UTF-8')
32
33	def log(self, category, level, message):
34		print("{}: {}".format(self.categoryName(category), message))