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 mLogFilterSave(const struct mLogFilter*, struct mCoreConfig*);
51void mLogFilterSet(struct mLogFilter*, const char* category, int levels);
52void mLogFilterReset(struct mLogFilter*, const char* category);
53bool mLogFilterTest(const struct mLogFilter*, int category, enum mLogLevel level);
54int mLogFilterLevels(const struct mLogFilter*, int category);
55
56ATTRIBUTE_FORMAT(printf, 3, 4)
57void mLog(int category, enum mLogLevel level, const char* format, ...);
58
59#define mLOG(CATEGORY, LEVEL, ...) mLog(_mLOG_CAT_ ## CATEGORY, mLOG_ ## LEVEL, __VA_ARGS__)
60
61#define mLOG_DECLARE_CATEGORY(CATEGORY) extern int _mLOG_CAT_ ## CATEGORY;
62#define mLOG_DEFINE_CATEGORY(CATEGORY, NAME, ID) \
63 int _mLOG_CAT_ ## CATEGORY; \
64 CONSTRUCTOR(_mLOG_CAT_ ## CATEGORY ## _INIT) { \
65 _mLOG_CAT_ ## CATEGORY = mLogGenerateCategory(NAME, ID); \
66 }
67
68MGBA_EXPORT mLOG_DECLARE_CATEGORY(STATUS)
69
70CXX_GUARD_END
71
72#endif