all repos — mgba @ c1a4f17ebd812c37a2b732391e95c504d7456e1f

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