Log.h 3.4 KB

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