all repos — mgba @ 0e40168a1b6b2e661babc1e9a8e0f87b65dbe02c

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