log.h 3.9 KB

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