all repos — mgba @ b782d902e63e7046b2a0f6b32cb129ef328fe9c2

mGBA Game Boy Advance Emulator

src/core/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 "log.h"
 7
 8#include "core/thread.h"
 9
10#define MAX_CATEGORY 64
11
12static struct mLogger* _defaultLogger = NULL;
13
14struct mLogger* mLogGetContext(void) {
15	struct mLogger* logger = mCoreThreadLogger();
16	if (logger) {
17		return logger;
18	}
19	return _defaultLogger;
20}
21
22void mLogSetDefaultLogger(struct mLogger* logger) {
23	_defaultLogger = logger;
24}
25
26static int _category = 0;
27static const char* _categoryNames[MAX_CATEGORY];
28
29int mLogGenerateCategory(const char* name) {
30	++_category;
31	if (_category < MAX_CATEGORY) {
32		_categoryNames[_category] = name;
33	}
34	return _category;
35}
36
37const char* mLogCategoryName(int category) {
38	if (category < MAX_CATEGORY) {
39		return _categoryNames[category];
40	}
41	return 0;
42}
43
44mLOG_DEFINE_CATEGORY(STATUS, "Status")