log.h 3.7 KB

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