log.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 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_BPC, ///< The BPC service
  62. Service_BTDRV, ///< The Bluetooth driver service
  63. Service_BTM, ///< The BTM service
  64. Service_Capture, ///< The capture service
  65. Service_ERPT, ///< The error reporting service
  66. Service_ETicket, ///< The ETicket service
  67. Service_EUPLD, ///< The error upload service
  68. Service_Fatal, ///< The Fatal service
  69. Service_FGM, ///< The FGM service
  70. Service_Friend, ///< The friend service
  71. Service_FS, ///< The FS (Filesystem) service
  72. Service_GRC, ///< The game recording service
  73. Service_HID, ///< The HID (Human interface device) service
  74. Service_IRS, ///< The IRS service
  75. Service_LBL, ///< The LBL (LCD backlight) service
  76. Service_LDN, ///< The LDN (Local domain network) service
  77. Service_LDR, ///< The loader service
  78. Service_LM, ///< The LM (Logger) service
  79. Service_Migration, ///< The migration service
  80. Service_Mii, ///< The Mii service
  81. Service_MM, ///< The MM (Multimedia) service
  82. Service_NCM, ///< The NCM service
  83. Service_NFC, ///< The NFC (Near-field communication) service
  84. Service_NFP, ///< The NFP service
  85. Service_NIFM, ///< The NIFM (Network interface) service
  86. Service_NIM, ///< The NIM service
  87. Service_NPNS, ///< The NPNS service
  88. Service_NS, ///< The NS services
  89. Service_NVDRV, ///< The NVDRV (Nvidia driver) service
  90. Service_PCIE, ///< The PCIe service
  91. Service_PCTL, ///< The PCTL (Parental control) service
  92. Service_PCV, ///< The PCV service
  93. Service_PM, ///< The PM service
  94. Service_PREPO, ///< The PREPO (Play report) service
  95. Service_PSC, ///< The PSC service
  96. Service_PSM, ///< The PSM service
  97. Service_SET, ///< The SET (Settings) service
  98. Service_SM, ///< The SM (Service manager) service
  99. Service_SPL, ///< The SPL service
  100. Service_SSL, ///< The SSL service
  101. Service_TCAP, ///< The TCAP service.
  102. Service_Time, ///< The time service
  103. Service_USB, ///< The USB (Universal Serial Bus) service
  104. Service_VI, ///< The VI (Video interface) service
  105. Service_WLAN, ///< The WLAN (Wireless local area network) service
  106. HW, ///< Low-level hardware emulation
  107. HW_Memory, ///< Memory-map and address translation
  108. HW_LCD, ///< LCD register emulation
  109. HW_GPU, ///< GPU control emulation
  110. HW_AES, ///< AES engine emulation
  111. IPC, ///< IPC interface
  112. Frontend, ///< Emulator UI
  113. Render, ///< Emulator video output and hardware acceleration
  114. Render_Software, ///< Software renderer backend
  115. Render_OpenGL, ///< OpenGL backend
  116. Render_Vulkan, ///< Vulkan backend
  117. Audio, ///< Audio emulation
  118. Audio_DSP, ///< The HLE implementation of the DSP
  119. Audio_Sink, ///< Emulator audio output backend
  120. Loader, ///< ROM loader
  121. CheatEngine, ///< Memory manipulation and engine VM functions
  122. Crypto, ///< Cryptographic engine/functions
  123. Input, ///< Input emulation
  124. Network, ///< Network emulation
  125. WebService, ///< Interface to yuzu Web Services
  126. Count ///< Total number of logging classes
  127. };
  128. /// Logs a message to the global logger, using fmt
  129. void FmtLogMessageImpl(Class log_class, Level log_level, const char* filename,
  130. unsigned int line_num, const char* function, const char* format,
  131. const fmt::format_args& args);
  132. template <typename... Args>
  133. void FmtLogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_num,
  134. const char* function, const char* format, const Args&... args) {
  135. FmtLogMessageImpl(log_class, log_level, filename, line_num, function, format,
  136. fmt::make_format_args(args...));
  137. }
  138. } // namespace Log
  139. #ifdef _DEBUG
  140. #define LOG_TRACE(log_class, ...) \
  141. ::Log::FmtLogMessage(::Log::Class::log_class, ::Log::Level::Trace, \
  142. ::Log::TrimSourcePath(__FILE__), __LINE__, __func__, __VA_ARGS__)
  143. #else
  144. #define LOG_TRACE(log_class, fmt, ...) (void(0))
  145. #endif
  146. #define LOG_DEBUG(log_class, ...) \
  147. ::Log::FmtLogMessage(::Log::Class::log_class, ::Log::Level::Debug, \
  148. ::Log::TrimSourcePath(__FILE__), __LINE__, __func__, __VA_ARGS__)
  149. #define LOG_INFO(log_class, ...) \
  150. ::Log::FmtLogMessage(::Log::Class::log_class, ::Log::Level::Info, \
  151. ::Log::TrimSourcePath(__FILE__), __LINE__, __func__, __VA_ARGS__)
  152. #define LOG_WARNING(log_class, ...) \
  153. ::Log::FmtLogMessage(::Log::Class::log_class, ::Log::Level::Warning, \
  154. ::Log::TrimSourcePath(__FILE__), __LINE__, __func__, __VA_ARGS__)
  155. #define LOG_ERROR(log_class, ...) \
  156. ::Log::FmtLogMessage(::Log::Class::log_class, ::Log::Level::Error, \
  157. ::Log::TrimSourcePath(__FILE__), __LINE__, __func__, __VA_ARGS__)
  158. #define LOG_CRITICAL(log_class, ...) \
  159. ::Log::FmtLogMessage(::Log::Class::log_class, ::Log::Level::Critical, \
  160. ::Log::TrimSourcePath(__FILE__), __LINE__, __func__, __VA_ARGS__)