diff options
Diffstat (limited to 'src/common/log.h')
| -rw-r--r-- | src/common/log.h | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/src/common/log.h b/src/common/log.h new file mode 100644 index 000000000..432a307f0 --- /dev/null +++ b/src/common/log.h | |||
| @@ -0,0 +1,155 @@ | |||
| 1 | // Copyright 2013 Dolphin Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #ifndef _LOG_H_ | ||
| 6 | #define _LOG_H_ | ||
| 7 | |||
| 8 | #define NOTICE_LEVEL 1 // VERY important information that is NOT errors. Like startup and OSReports. | ||
| 9 | #define ERROR_LEVEL 2 // Critical errors | ||
| 10 | #define WARNING_LEVEL 3 // Something is suspicious. | ||
| 11 | #define INFO_LEVEL 4 // General information. | ||
| 12 | #define DEBUG_LEVEL 5 // Detailed debugging - might make things slow. | ||
| 13 | |||
| 14 | namespace LogTypes | ||
| 15 | { | ||
| 16 | |||
| 17 | enum LOG_TYPE { | ||
| 18 | ACTIONREPLAY, | ||
| 19 | AUDIO, | ||
| 20 | AUDIO_INTERFACE, | ||
| 21 | BOOT, | ||
| 22 | COMMANDPROCESSOR, | ||
| 23 | COMMON, | ||
| 24 | CONSOLE, | ||
| 25 | DISCIO, | ||
| 26 | FILEMON, | ||
| 27 | DSPHLE, | ||
| 28 | DSPLLE, | ||
| 29 | DSP_MAIL, | ||
| 30 | DSPINTERFACE, | ||
| 31 | DVDINTERFACE, | ||
| 32 | DYNA_REC, | ||
| 33 | EXPANSIONINTERFACE, | ||
| 34 | GDB_STUB, | ||
| 35 | ARM11, | ||
| 36 | GPFIFO, | ||
| 37 | OSHLE, | ||
| 38 | MASTER_LOG, | ||
| 39 | MEMMAP, | ||
| 40 | MEMCARD_MANAGER, | ||
| 41 | OSREPORT, | ||
| 42 | PAD, | ||
| 43 | PROCESSORINTERFACE, | ||
| 44 | PIXELENGINE, | ||
| 45 | SERIALINTERFACE, | ||
| 46 | SP1, | ||
| 47 | STREAMINGINTERFACE, | ||
| 48 | VIDEO, | ||
| 49 | VIDEOINTERFACE, | ||
| 50 | LOADER, | ||
| 51 | FILESYS, | ||
| 52 | WII_IPC_DVD, | ||
| 53 | WII_IPC_ES, | ||
| 54 | WII_IPC_FILEIO, | ||
| 55 | WII_IPC_HID, | ||
| 56 | WII_IPC_HLE, | ||
| 57 | WII_IPC_NET, | ||
| 58 | WII_IPC_WC24, | ||
| 59 | WII_IPC_SSL, | ||
| 60 | RENDER, | ||
| 61 | LCD, | ||
| 62 | HW, | ||
| 63 | TIME, | ||
| 64 | NETPLAY, | ||
| 65 | |||
| 66 | NUMBER_OF_LOGS // Must be last | ||
| 67 | }; | ||
| 68 | |||
| 69 | // FIXME: should this be removed? | ||
| 70 | enum LOG_LEVELS { | ||
| 71 | LNOTICE = NOTICE_LEVEL, | ||
| 72 | LERROR = ERROR_LEVEL, | ||
| 73 | LWARNING = WARNING_LEVEL, | ||
| 74 | LINFO = INFO_LEVEL, | ||
| 75 | LDEBUG = DEBUG_LEVEL, | ||
| 76 | }; | ||
| 77 | |||
| 78 | #define LOGTYPES_LEVELS LogTypes::LOG_LEVELS | ||
| 79 | #define LOGTYPES_TYPE LogTypes::LOG_TYPE | ||
| 80 | |||
| 81 | } // namespace | ||
| 82 | |||
| 83 | void GenericLog(LOGTYPES_LEVELS level, LOGTYPES_TYPE type, | ||
| 84 | const char *file, int line, const char *fmt, ...) | ||
| 85 | #ifdef __GNUC__ | ||
| 86 | __attribute__((format(printf, 5, 6))) | ||
| 87 | #endif | ||
| 88 | ; | ||
| 89 | |||
| 90 | #if defined LOGGING || defined _DEBUG || defined DEBUGFAST | ||
| 91 | #define MAX_LOGLEVEL DEBUG_LEVEL | ||
| 92 | #else | ||
| 93 | #ifndef MAX_LOGLEVEL | ||
| 94 | #define MAX_LOGLEVEL WARNING_LEVEL | ||
| 95 | #endif // loglevel | ||
| 96 | #endif // logging | ||
| 97 | |||
| 98 | #ifdef GEKKO | ||
| 99 | #define GENERIC_LOG(t, v, ...) | ||
| 100 | #else | ||
| 101 | // Let the compiler optimize this out | ||
| 102 | #define GENERIC_LOG(t, v, ...) { \ | ||
| 103 | if (v <= MAX_LOGLEVEL) \ | ||
| 104 | GenericLog(v, t, __FILE__, __LINE__, __VA_ARGS__); \ | ||
| 105 | } | ||
| 106 | #endif | ||
| 107 | |||
| 108 | #define ERROR_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LERROR, __VA_ARGS__) } while (0) | ||
| 109 | #define WARN_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LWARNING, __VA_ARGS__) } while (0) | ||
| 110 | #define NOTICE_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LNOTICE, __VA_ARGS__) } while (0) | ||
| 111 | #define INFO_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LINFO, __VA_ARGS__) } while (0) | ||
| 112 | #define DEBUG_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LDEBUG, __VA_ARGS__) } while (0) | ||
| 113 | |||
| 114 | #if MAX_LOGLEVEL >= DEBUG_LEVEL | ||
| 115 | #define _dbg_assert_(_t_, _a_) \ | ||
| 116 | if (!(_a_)) {\ | ||
| 117 | ERROR_LOG(_t_, "Error...\n\n Line: %d\n File: %s\n Time: %s\n\nIgnore and continue?", \ | ||
| 118 | __LINE__, __FILE__, __TIME__); \ | ||
| 119 | if (!PanicYesNo("*** Assertion (see log)***\n")) {Crash();} \ | ||
| 120 | } | ||
| 121 | #define _dbg_assert_msg_(_t_, _a_, ...)\ | ||
| 122 | if (!(_a_)) {\ | ||
| 123 | ERROR_LOG(_t_, __VA_ARGS__); \ | ||
| 124 | if (!PanicYesNo(__VA_ARGS__)) {Crash();} \ | ||
| 125 | } | ||
| 126 | #define _dbg_update_() Host_UpdateLogDisplay(); | ||
| 127 | |||
| 128 | #else // not debug | ||
| 129 | #define _dbg_update_() ; | ||
| 130 | |||
| 131 | #ifndef _dbg_assert_ | ||
| 132 | #define _dbg_assert_(_t_, _a_) {} | ||
| 133 | #define _dbg_assert_msg_(_t_, _a_, _desc_, ...) {} | ||
| 134 | #endif // dbg_assert | ||
| 135 | #endif // MAX_LOGLEVEL DEBUG | ||
| 136 | |||
| 137 | #define _assert_(_a_) _dbg_assert_(MASTER_LOG, _a_) | ||
| 138 | |||
| 139 | #ifndef GEKKO | ||
| 140 | #ifdef _WIN32 | ||
| 141 | #define _assert_msg_(_t_, _a_, _fmt_, ...) \ | ||
| 142 | if (!(_a_)) {\ | ||
| 143 | if (!PanicYesNo(_fmt_, __VA_ARGS__)) {Crash();} \ | ||
| 144 | } | ||
| 145 | #else // not win32 | ||
| 146 | #define _assert_msg_(_t_, _a_, _fmt_, ...) \ | ||
| 147 | if (!(_a_)) {\ | ||
| 148 | if (!PanicYesNo(_fmt_, ##__VA_ARGS__)) {Crash();} \ | ||
| 149 | } | ||
| 150 | #endif // WIN32 | ||
| 151 | #else // GEKKO | ||
| 152 | #define _assert_msg_(_t_, _a_, _fmt_, ...) | ||
| 153 | #endif | ||
| 154 | |||
| 155 | #endif // _LOG_H_ | ||