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