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
13#include <mgba-util/table.h>
14
15enum mLogLevel {
16 mLOG_FATAL = 0x01,
17 mLOG_ERROR = 0x02,
18 mLOG_WARN = 0x04,
19 mLOG_INFO = 0x08,
20 mLOG_DEBUG = 0x10,
21 mLOG_STUB = 0x20,
22 mLOG_GAME_ERROR = 0x40,
23
24 mLOG_ALL = 0x7F
25};
26
27struct Table;
28struct mLogFilter {
29 int defaultLevels;
30 struct Table categories;
31 struct Table levels;
32};
33
34struct mLogger {
35 void (*log)(struct mLogger*, int category, enum mLogLevel level, const char* format, va_list args);
36 struct mLogFilter* filter;
37};
38
39struct mLogger* mLogGetContext(void);
40void mLogSetDefaultLogger(struct mLogger*);
41int mLogGenerateCategory(const char*, const char*);
42const char* mLogCategoryName(int);
43const char* mLogCategoryId(int);
44int mLogCategoryById(const char*);
45
46struct mCoreConfig;
47void mLogFilterInit(struct mLogFilter*);
48void mLogFilterDeinit(struct mLogFilter*);
49void mLogFilterLoad(struct mLogFilter*, const struct mCoreConfig*);
50void mLogFilterSet(struct mLogFilter*, const char* category, int levels);
51bool mLogFilterTest(struct mLogFilter*, int category, enum mLogLevel level);
52
53ATTRIBUTE_FORMAT(printf, 3, 4)
54void mLog(int category, enum mLogLevel level, const char* format, ...);
55
56#define mLOG(CATEGORY, LEVEL, ...) mLog(_mLOG_CAT_ ## CATEGORY (), mLOG_ ## LEVEL, __VA_ARGS__)
57
58#define mLOG_DECLARE_CATEGORY(CATEGORY) int _mLOG_CAT_ ## CATEGORY (void); extern const char* _mLOG_CAT_ ## CATEGORY ## _ID;
59#define mLOG_DEFINE_CATEGORY(CATEGORY, NAME, ID) \
60 int _mLOG_CAT_ ## CATEGORY (void) { \
61 static int category = 0; \
62 if (!category) { \
63 category = mLogGenerateCategory(NAME, ID); \
64 } \
65 return category; \
66 } \
67 const char* _mLOG_CAT_ ## CATEGORY ## _ID = ID;
68
69mLOG_DECLARE_CATEGORY(STATUS)
70
71CXX_GUARD_END
72
73#endif