log.h 7.7 KB

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