log.h 4.0 KB

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