log.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <fmt/format.h>
  6. #include "common/common_types.h"
  7. namespace Common::Log {
  8. // trims up to and including the last of ../, ..\, src/, src\ in a string
  9. constexpr const char* TrimSourcePath(std::string_view source) {
  10. const auto rfind = [source](const std::string_view match) {
  11. return source.rfind(match) == source.npos ? 0 : (source.rfind(match) + match.size());
  12. };
  13. auto idx = std::max({rfind("src/"), rfind("src\\"), rfind("../"), rfind("..\\")});
  14. return source.data() + idx;
  15. }
  16. /// Specifies the severity or level of detail of the log message.
  17. enum class Level : u8 {
  18. Trace, ///< Extremely detailed and repetitive debugging information that is likely to
  19. ///< pollute logs.
  20. Debug, ///< Less detailed debugging information.
  21. Info, ///< Status information from important points during execution.
  22. Warning, ///< Minor or potential problems found during execution of a task.
  23. Error, ///< Major problems found during execution of a task that prevent it from being
  24. ///< completed.
  25. Critical, ///< Major problems during execution that threaten the stability of the entire
  26. ///< application.
  27. Count ///< Total number of logging levels
  28. };
  29. typedef u8 ClassType;
  30. /**
  31. * Specifies the sub-system that generated the log message.
  32. *
  33. * @note If you add a new entry here, also add a corresponding one to `ALL_LOG_CLASSES` in
  34. * backend.cpp.
  35. */
  36. enum class Class : ClassType {
  37. Log, ///< Messages about the log system itself
  38. Common, ///< Library routines
  39. Common_Filesystem, ///< Filesystem interface library
  40. Common_Memory, ///< Memory mapping and management functions
  41. Core, ///< LLE emulation core
  42. Core_ARM, ///< ARM CPU core
  43. Core_Timing, ///< CoreTiming functions
  44. Config, ///< Emulator configuration (including commandline)
  45. Debug, ///< Debugging tools
  46. Debug_Emulated, ///< Debug messages from the emulated programs
  47. Debug_GPU, ///< GPU debugging tools
  48. Debug_Breakpoint, ///< Logging breakpoints and watchpoints
  49. Debug_GDBStub, ///< GDB Stub
  50. Kernel, ///< The HLE implementation of the CTR kernel
  51. Kernel_SVC, ///< Kernel system calls
  52. Service, ///< HLE implementation of system services. Each major service
  53. ///< should have its own subclass.
  54. Service_ACC, ///< The ACC (Accounts) service
  55. Service_AM, ///< The AM (Applet manager) service
  56. Service_AOC, ///< The AOC (AddOn Content) service
  57. Service_APM, ///< The APM (Performance) service
  58. Service_ARP, ///< The ARP service
  59. Service_Audio, ///< The Audio (Audio control) service
  60. Service_BCAT, ///< The BCAT service
  61. Service_BGTC, ///< The BGTC (Background Task Controller) service
  62. Service_BPC, ///< The BPC service
  63. Service_BTDRV, ///< The Bluetooth driver service
  64. Service_BTM, ///< The BTM service
  65. Service_Capture, ///< The capture service
  66. Service_ERPT, ///< The error reporting service
  67. Service_ETicket, ///< The ETicket service
  68. Service_EUPLD, ///< The error upload service
  69. Service_Fatal, ///< The Fatal service
  70. Service_FGM, ///< The FGM service
  71. Service_Friend, ///< The friend service
  72. Service_FS, ///< The FS (Filesystem) service
  73. Service_GRC, ///< The game recording service
  74. Service_HID, ///< The HID (Human interface device) service
  75. Service_IRS, ///< The IRS service
  76. Service_LBL, ///< The LBL (LCD backlight) service
  77. Service_LDN, ///< The LDN (Local domain network) service
  78. Service_LDR, ///< The loader service
  79. Service_LM, ///< The LM (Logger) service
  80. Service_Migration, ///< The migration service
  81. Service_Mii, ///< The Mii service
  82. Service_MM, ///< The MM (Multimedia) service
  83. Service_NCM, ///< The NCM service
  84. Service_NFC, ///< The NFC (Near-field communication) service
  85. Service_NFP, ///< The NFP service
  86. Service_NIFM, ///< The NIFM (Network interface) service
  87. Service_NIM, ///< The NIM service
  88. Service_NPNS, ///< The NPNS service
  89. Service_NS, ///< The NS services
  90. Service_NVDRV, ///< The NVDRV (Nvidia driver) service
  91. Service_OLSC, ///< The OLSC service
  92. Service_PCIE, ///< The PCIe service
  93. Service_PCTL, ///< The PCTL (Parental control) service
  94. Service_PCV, ///< The PCV service
  95. Service_PM, ///< The PM service
  96. Service_PREPO, ///< The PREPO (Play report) service
  97. Service_PSC, ///< The PSC service
  98. Service_PSM, ///< The PSM service
  99. Service_SET, ///< The SET (Settings) service
  100. Service_SM, ///< The SM (Service manager) service
  101. Service_SPL, ///< The SPL service
  102. Service_SSL, ///< The SSL service
  103. Service_TCAP, ///< The TCAP service.
  104. Service_Time, ///< The time service
  105. Service_USB, ///< The USB (Universal Serial Bus) service
  106. Service_VI, ///< The VI (Video interface) service
  107. Service_WLAN, ///< The WLAN (Wireless local area network) service
  108. HW, ///< Low-level hardware emulation
  109. HW_Memory, ///< Memory-map and address translation
  110. HW_LCD, ///< LCD register emulation
  111. HW_GPU, ///< GPU control emulation
  112. HW_AES, ///< AES engine emulation
  113. IPC, ///< IPC interface
  114. Frontend, ///< Emulator UI
  115. Render, ///< Emulator video output and hardware acceleration
  116. Render_Software, ///< Software renderer backend
  117. Render_OpenGL, ///< OpenGL backend
  118. Render_Vulkan, ///< Vulkan backend
  119. Audio, ///< Audio emulation
  120. Audio_DSP, ///< The HLE implementation of the DSP
  121. Audio_Sink, ///< Emulator audio output backend
  122. Loader, ///< ROM loader
  123. CheatEngine, ///< Memory manipulation and engine VM functions
  124. Crypto, ///< Cryptographic engine/functions
  125. Input, ///< Input emulation
  126. Network, ///< Network emulation
  127. WebService, ///< Interface to yuzu Web Services
  128. Count ///< Total number of logging classes
  129. };
  130. /// Logs a message to the global logger, using fmt
  131. void FmtLogMessageImpl(Class log_class, Level log_level, const char* filename,
  132. unsigned int line_num, const char* function, const char* format,
  133. const fmt::format_args& args);
  134. template <typename... Args>
  135. void FmtLogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_num,
  136. const char* function, const char* format, const Args&... args) {
  137. FmtLogMessageImpl(log_class, log_level, filename, line_num, function, format,
  138. fmt::make_format_args(args...));
  139. }
  140. } // namespace Common::Log
  141. #ifdef _DEBUG
  142. #define LOG_TRACE(log_class, ...) \
  143. Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Trace, \
  144. Common::Log::TrimSourcePath(__FILE__), __LINE__, __func__, \
  145. __VA_ARGS__)
  146. #else
  147. #define LOG_TRACE(log_class, fmt, ...) (void(0))
  148. #endif
  149. #define LOG_DEBUG(log_class, ...) \
  150. Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Debug, \
  151. Common::Log::TrimSourcePath(__FILE__), __LINE__, __func__, \
  152. __VA_ARGS__)
  153. #define LOG_INFO(log_class, ...) \
  154. Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Info, \
  155. Common::Log::TrimSourcePath(__FILE__), __LINE__, __func__, \
  156. __VA_ARGS__)
  157. #define LOG_WARNING(log_class, ...) \
  158. Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Warning, \
  159. Common::Log::TrimSourcePath(__FILE__), __LINE__, __func__, \
  160. __VA_ARGS__)
  161. #define LOG_ERROR(log_class, ...) \
  162. Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Error, \
  163. Common::Log::TrimSourcePath(__FILE__), __LINE__, __func__, \
  164. __VA_ARGS__)
  165. #define LOG_CRITICAL(log_class, ...) \
  166. Common::Log::FmtLogMessage(Common::Log::Class::log_class, Common::Log::Level::Critical, \
  167. Common::Log::TrimSourcePath(__FILE__), __LINE__, __func__, \
  168. __VA_ARGS__)