all repos — mgba @ f17e3276265594b09218aaec4f8044a026ecb194

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 = NULL;
16#ifndef DISABLE_THREADING
17	logger = mCoreThreadLogger();
18#endif
19	if (logger) {
20		return logger;
21	}
22	return _defaultLogger;
23}
24
25void mLogSetDefaultLogger(struct mLogger* logger) {
26	_defaultLogger = logger;
27}
28
29static int _category = 0;
30static const char* _categoryNames[MAX_CATEGORY];
31
32int mLogGenerateCategory(const char* name) {
33	++_category;
34	if (_category < MAX_CATEGORY) {
35		_categoryNames[_category] = name;
36	}
37	return _category;
38}
39
40const char* mLogCategoryName(int category) {
41	if (category < MAX_CATEGORY) {
42		return _categoryNames[category];
43	}
44	return 0;
45}
46
47mLOG_DEFINE_CATEGORY(STATUS, "Status")