log.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 LOGGING
  7. enum {
  8. OS_LEVEL, // Printed by the emulated operating system
  9. NOTICE_LEVEL, // VERY important information that is NOT errors. Like startup and OSReports.
  10. ERROR_LEVEL, // Critical errors
  11. WARNING_LEVEL, // Something is suspicious.
  12. INFO_LEVEL, // General information.
  13. DEBUG_LEVEL, // Detailed debugging - might make things slow.
  14. };
  15. namespace LogTypes
  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. GSP,
  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. KERNEL,
  57. SVC,
  58. NDMA,
  59. HLE,
  60. RENDER,
  61. LCD,
  62. HW,
  63. TIME,
  64. NETPLAY,
  65. NUMBER_OF_LOGS // Must be last
  66. };
  67. // FIXME: should this be removed?
  68. enum LOG_LEVELS {
  69. LOS = OS_LEVEL,
  70. LNOTICE = NOTICE_LEVEL,
  71. LERROR = ERROR_LEVEL,
  72. LWARNING = WARNING_LEVEL,
  73. LINFO = INFO_LEVEL,
  74. LDEBUG = DEBUG_LEVEL,
  75. };
  76. #define LOGTYPES_LEVELS LogTypes::LOG_LEVELS
  77. #define LOGTYPES_TYPE LogTypes::LOG_TYPE
  78. } // namespace
  79. void GenericLog(LOGTYPES_LEVELS level, LOGTYPES_TYPE type, const char*file, int line,
  80. const char* function, const char* fmt, ...)
  81. #ifdef __GNUC__
  82. __attribute__((format(printf, 6, 7)))
  83. #endif
  84. ;
  85. #if defined LOGGING || defined _DEBUG || defined DEBUGFAST
  86. #define MAX_LOGLEVEL DEBUG_LEVEL
  87. #else
  88. #ifndef MAX_LOGLEVEL
  89. #define MAX_LOGLEVEL WARNING_LEVEL
  90. #endif // loglevel
  91. #endif // logging
  92. #ifdef _WIN32
  93. #ifndef __func__
  94. #define __func__ __FUNCTION__
  95. #endif
  96. #endif
  97. // Let the compiler optimize this out
  98. #define GENERIC_LOG(t, v, ...) { \
  99. if (v <= MAX_LOGLEVEL) \
  100. GenericLog(v, t, __FILE__, __LINE__, __func__, __VA_ARGS__); \
  101. }
  102. #define OS_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LOS, __VA_ARGS__) } while (0)
  103. #define ERROR_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LERROR, __VA_ARGS__) } while (0)
  104. #define WARN_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LWARNING, __VA_ARGS__) } while (0)
  105. #define NOTICE_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LNOTICE, __VA_ARGS__) } while (0)
  106. #define INFO_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LINFO, __VA_ARGS__) } while (0)
  107. #define DEBUG_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LDEBUG, __VA_ARGS__) } while (0)
  108. #if MAX_LOGLEVEL >= DEBUG_LEVEL
  109. #define _dbg_assert_(_t_, _a_) \
  110. if (!(_a_)) {\
  111. ERROR_LOG(_t_, "Error...\n\n Line: %d\n File: %s\n Time: %s\n\nIgnore and continue?", \
  112. __LINE__, __FILE__, __TIME__); \
  113. if (!PanicYesNo("*** Assertion (see log)***\n")) {Crash();} \
  114. }
  115. #define _dbg_assert_msg_(_t_, _a_, ...)\
  116. if (!(_a_)) {\
  117. ERROR_LOG(_t_, __VA_ARGS__); \
  118. if (!PanicYesNo(__VA_ARGS__)) {Crash();} \
  119. }
  120. #define _dbg_update_() Host_UpdateLogDisplay();
  121. #else // not debug
  122. #define _dbg_update_() ;
  123. #ifndef _dbg_assert_
  124. #define _dbg_assert_(_t_, _a_) {}
  125. #define _dbg_assert_msg_(_t_, _a_, _desc_, ...) {}
  126. #endif // dbg_assert
  127. #endif // MAX_LOGLEVEL DEBUG
  128. #define _assert_(_a_) _dbg_assert_(MASTER_LOG, _a_)
  129. #ifndef GEKKO
  130. #ifdef _WIN32
  131. #define _assert_msg_(_t_, _a_, _fmt_, ...) \
  132. if (!(_a_)) {\
  133. if (!PanicYesNo(_fmt_, __VA_ARGS__)) {Crash();} \
  134. }
  135. #else // not win32
  136. #define _assert_msg_(_t_, _a_, _fmt_, ...) \
  137. if (!(_a_)) {\
  138. if (!PanicYesNo(_fmt_, ##__VA_ARGS__)) {Crash();} \
  139. }
  140. #endif // WIN32
  141. #else // GEKKO
  142. #define _assert_msg_(_t_, _a_, _fmt_, ...)
  143. #endif
  144. #endif // _LOG_H_