all repos — mgba @ 000f232c582b0981b66d48d7af799e97faffad8e

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*, const char*);
32const char* mLogCategoryName(int);
33const char* mLogCategoryId(int);
34int mLogCategoryById(const char*);
35
36ATTRIBUTE_FORMAT(printf, 3, 4)
37void mLog(int category, enum mLogLevel level, const char* format, ...);
38
39#define mLOG(CATEGORY, LEVEL, ...) mLog(_mLOG_CAT_ ## CATEGORY (), mLOG_ ## LEVEL, __VA_ARGS__)
40
41#define mLOG_DECLARE_CATEGORY(CATEGORY) int _mLOG_CAT_ ## CATEGORY (void); extern const char* _mLOG_CAT_ ## CATEGORY ## _ID;
42#define mLOG_DEFINE_CATEGORY(CATEGORY, NAME, ID) \
43	int _mLOG_CAT_ ## CATEGORY (void) { \
44		static int category = 0; \
45		if (!category) { \
46			category = mLogGenerateCategory(NAME, ID); \
47		} \
48		return category; \
49	} \
50	const char* _mLOG_CAT_ ## CATEGORY ## _ID = ID;
51
52mLOG_DECLARE_CATEGORY(STATUS)
53
54CXX_GUARD_END
55
56#endif