log.h 7.9 KB

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