all repos — mgba @ fa884d071ecaa3e05ff20b45a67bf9500dd3d6b6

mGBA Game Boy Advance Emulator

include/mgba/core/log.h (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#ifndef M_LOG_H
 7#define M_LOG_H
 8
 9#include <mgba-util/common.h>
10
11CXX_GUARD_START
12
13enum mLogLevel {
14	mLOG_FATAL = 0x01,
15	mLOG_ERROR = 0x02,
16	mLOG_WARN = 0x04,
17	mLOG_INFO = 0x08,
18	mLOG_DEBUG = 0x10,
19	mLOG_STUB = 0x20,
20	mLOG_GAME_ERROR = 0x40,
21
22	mLOG_ALL = 0x7F
23};
24
25struct mLogger {
26	void (*log)(struct mLogger*, int category, enum mLogLevel level, const char* format, va_list args);
27};
28
29struct mLogger* mLogGetContext(void);
30void mLogSetDefaultLogger(struct mLogger*);
31int mLogGenerateCategory(const char*);
32const char* mLogCategoryName(int);
33
34ATTRIBUTE_FORMAT(printf, 3, 4)
35void mLog(int category, enum mLogLevel level, const char* format, ...);
36
37#define mLOG(CATEGORY, LEVEL, ...) mLog(_mLOG_CAT_ ## CATEGORY (), mLOG_ ## LEVEL, __VA_ARGS__)
38
39#define mLOG_DECLARE_CATEGORY(CATEGORY) int _mLOG_CAT_ ## CATEGORY (void);
40#define mLOG_DEFINE_CATEGORY(CATEGORY, NAME) \
41	int _mLOG_CAT_ ## CATEGORY (void) { \
42		static int category = 0; \
43		if (!category) { \
44			category = mLogGenerateCategory(NAME); \
45		} \
46		return category; \
47	}
48
49mLOG_DECLARE_CATEGORY(STATUS)
50
51CXX_GUARD_END
52
53#endif