log.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. DISCIO,
  27. FILEMON,
  28. DSPHLE,
  29. DSPLLE,
  30. DSP_MAIL,
  31. DSPINTERFACE,
  32. DVDINTERFACE,
  33. DYNA_REC,
  34. EXPANSIONINTERFACE,
  35. GDB_STUB,
  36. ARM11,
  37. GSP,
  38. OSHLE,
  39. MASTER_LOG,
  40. MEMMAP,
  41. MEMCARD_MANAGER,
  42. OSREPORT,
  43. PAD,
  44. PROCESSORINTERFACE,
  45. PIXELENGINE,
  46. SERIALINTERFACE,
  47. SP1,
  48. STREAMINGINTERFACE,
  49. VIDEO,
  50. VIDEOINTERFACE,
  51. LOADER,
  52. FILESYS,
  53. WII_IPC_DVD,
  54. WII_IPC_ES,
  55. WII_IPC_FILEIO,
  56. WII_IPC_HID,
  57. KERNEL,
  58. SVC,
  59. NDMA,
  60. HLE,
  61. RENDER,
  62. GPU,
  63. HW,
  64. TIME,
  65. NETPLAY,
  66. NUMBER_OF_LOGS // Must be last
  67. };
  68. // FIXME: should this be removed?
  69. enum LOG_LEVELS {
  70. LOS = OS_LEVEL,
  71. LNOTICE = NOTICE_LEVEL,
  72. LERROR = ERROR_LEVEL,
  73. LWARNING = WARNING_LEVEL,
  74. LINFO = INFO_LEVEL,
  75. LDEBUG = DEBUG_LEVEL,
  76. };
  77. #define LOGTYPES_LEVELS LogTypes::LOG_LEVELS
  78. #define LOGTYPES_TYPE LogTypes::LOG_TYPE
  79. } // namespace
  80. void GenericLog(LOGTYPES_LEVELS level, LOGTYPES_TYPE type, const char*file, int line,
  81. const char* function, const char* fmt, ...)
  82. #ifdef __GNUC__
  83. __attribute__((format(printf, 6, 7)))
  84. #endif
  85. ;
  86. #if defined LOGGING || defined _DEBUG || defined DEBUGFAST
  87. #define MAX_LOGLEVEL LDEBUG
  88. #else
  89. #ifndef MAX_LOGLEVEL
  90. #define MAX_LOGLEVEL LWARNING
  91. #endif // loglevel
  92. #endif // logging
  93. #ifdef _WIN32
  94. #ifndef __func__
  95. #define __func__ __FUNCTION__
  96. #endif
  97. #endif
  98. // Let the compiler optimize this out
  99. #define GENERIC_LOG(t, v, ...) { \
  100. if (v <= LogTypes::MAX_LOGLEVEL) \
  101. GenericLog(v, t, __FILE__, __LINE__, __func__, __VA_ARGS__); \
  102. }
  103. #define OS_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LOS, __VA_ARGS__) } while (0)
  104. #define ERROR_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LERROR, __VA_ARGS__) } while (0)
  105. #define WARN_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LWARNING, __VA_ARGS__) } while (0)
  106. #define NOTICE_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LNOTICE, __VA_ARGS__) } while (0)
  107. #define INFO_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LINFO, __VA_ARGS__) } while (0)
  108. #define DEBUG_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LDEBUG, __VA_ARGS__) } while (0)
  109. #if MAX_LOGLEVEL >= DEBUG_LEVEL
  110. #define _dbg_assert_(_t_, _a_) \
  111. if (!(_a_)) {\
  112. ERROR_LOG(_t_, "Error...\n\n Line: %d\n File: %s\n Time: %s\n\nIgnore and continue?", \
  113. __LINE__, __FILE__, __TIME__); \
  114. if (!PanicYesNo("*** Assertion (see log)***\n")) {Crash();} \
  115. }
  116. #define _dbg_assert_msg_(_t_, _a_, ...)\
  117. if (!(_a_)) {\
  118. ERROR_LOG(_t_, __VA_ARGS__); \
  119. if (!PanicYesNo(__VA_ARGS__)) {Crash();} \
  120. }
  121. #define _dbg_update_() Host_UpdateLogDisplay();
  122. #else // not debug
  123. #define _dbg_update_() ;
  124. #ifndef _dbg_assert_
  125. #define _dbg_assert_(_t_, _a_) {}
  126. #define _dbg_assert_msg_(_t_, _a_, _desc_, ...) {}
  127. #endif // dbg_assert
  128. #endif // MAX_LOGLEVEL DEBUG
  129. #define _assert_(_a_) _dbg_assert_(MASTER_LOG, _a_)
  130. #ifndef GEKKO
  131. #ifdef _WIN32
  132. #define _assert_msg_(_t_, _a_, _fmt_, ...) \
  133. if (!(_a_)) {\
  134. if (!PanicYesNo(_fmt_, __VA_ARGS__)) {Crash();} \
  135. }
  136. #else // not win32
  137. #define _assert_msg_(_t_, _a_, _fmt_, ...) \
  138. if (!(_a_)) {\
  139. if (!PanicYesNo(_fmt_, ##__VA_ARGS__)) {Crash();} \
  140. }
  141. #endif // WIN32
  142. #else // GEKKO
  143. #define _assert_msg_(_t_, _a_, _fmt_, ...)
  144. #endif