log.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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_Audio, ///< The Audio (Audio control) service
  51. Service_Fatal, ///< The Fatal service
  52. Service_Friend, ///< The friend service
  53. Service_FS, ///< The FS (Filesystem) service
  54. Service_HID, ///< The HID (Human interface device) service
  55. Service_LM, ///< The LM (Logger) service
  56. Service_NFP, ///< The NFP service
  57. Service_NIFM, ///< The NIFM (Network interface) service
  58. Service_NS, ///< The NS services
  59. Service_NVDRV, ///< The NVDRV (Nvidia driver) service
  60. Service_PCTL, ///< The PCTL (Parental control) service
  61. Service_PREPO, ///< The PREPO (Play report) service
  62. Service_SET, ///< The SET (Settings) service
  63. Service_SM, ///< The SM (Service manager) service
  64. Service_SPL, ///< The SPL service
  65. Service_SSL, ///< The SSL service
  66. Service_Time, ///< The time service
  67. Service_VI, ///< The VI (Video interface) service
  68. HW, ///< Low-level hardware emulation
  69. HW_Memory, ///< Memory-map and address translation
  70. HW_LCD, ///< LCD register emulation
  71. HW_GPU, ///< GPU control emulation
  72. HW_AES, ///< AES engine emulation
  73. IPC, ///< IPC interface
  74. Frontend, ///< Emulator UI
  75. Render, ///< Emulator video output and hardware acceleration
  76. Render_Software, ///< Software renderer backend
  77. Render_OpenGL, ///< OpenGL backend
  78. Audio, ///< Audio emulation
  79. Audio_DSP, ///< The HLE implementation of the DSP
  80. Audio_Sink, ///< Emulator audio output backend
  81. Loader, ///< ROM loader
  82. Input, ///< Input emulation
  83. Network, ///< Network emulation
  84. WebService, ///< Interface to yuzu Web Services
  85. Count ///< Total number of logging classes
  86. };
  87. /// Logs a message to the global logger.
  88. void LogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_num,
  89. const char* function,
  90. #ifdef _MSC_VER
  91. _Printf_format_string_
  92. #endif
  93. const char* format,
  94. ...)
  95. #ifdef __GNUC__
  96. __attribute__((format(printf, 6, 7)))
  97. #endif
  98. ;
  99. /// Logs a message to the global logger, using fmt
  100. void FmtLogMessageImpl(Class log_class, Level log_level, const char* filename,
  101. unsigned int line_num, const char* function, const char* format,
  102. const fmt::format_args& args);
  103. template <typename... Args>
  104. void FmtLogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_num,
  105. const char* function, const char* format, const Args&... args) {
  106. FmtLogMessageImpl(log_class, log_level, filename, line_num, function, format,
  107. fmt::make_args(args...));
  108. }
  109. } // namespace Log
  110. #define LOG_GENERIC(log_class, log_level, ...) \
  111. ::Log::LogMessage(log_class, log_level, __FILE__, __LINE__, __func__, __VA_ARGS__)
  112. #ifdef _DEBUG
  113. #define LOG_TRACE(log_class, ...) \
  114. LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Trace, __VA_ARGS__)
  115. #else
  116. #define LOG_TRACE(log_class, ...) (void(0))
  117. #endif
  118. #define LOG_DEBUG(log_class, ...) \
  119. LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Debug, __VA_ARGS__)
  120. #define LOG_INFO(log_class, ...) \
  121. LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Info, __VA_ARGS__)
  122. #define LOG_WARNING(log_class, ...) \
  123. LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Warning, __VA_ARGS__)
  124. #define LOG_ERROR(log_class, ...) \
  125. LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Error, __VA_ARGS__)
  126. #define LOG_CRITICAL(log_class, ...) \
  127. LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Critical, __VA_ARGS__)
  128. // Define the fmt lib macros
  129. #ifdef _DEBUG
  130. #define NGLOG_TRACE(log_class, ...) \
  131. ::Log::FmtLogMessage(::Log::Class::log_class, ::Log::Level::Trace, __FILE__, __LINE__, \
  132. __func__, __VA_ARGS__)
  133. #else
  134. #define NGLOG_TRACE(log_class, fmt, ...) (void(0))
  135. #endif
  136. #define NGLOG_DEBUG(log_class, ...) \
  137. ::Log::FmtLogMessage(::Log::Class::log_class, ::Log::Level::Debug, __FILE__, __LINE__, \
  138. __func__, __VA_ARGS__)
  139. #define NGLOG_INFO(log_class, ...) \
  140. ::Log::FmtLogMessage(::Log::Class::log_class, ::Log::Level::Info, __FILE__, __LINE__, \
  141. __func__, __VA_ARGS__)
  142. #define NGLOG_WARNING(log_class, ...) \
  143. ::Log::FmtLogMessage(::Log::Class::log_class, ::Log::Level::Warning, __FILE__, __LINE__, \
  144. __func__, __VA_ARGS__)
  145. #define NGLOG_ERROR(log_class, ...) \
  146. ::Log::FmtLogMessage(::Log::Class::log_class, ::Log::Level::Error, __FILE__, __LINE__, \
  147. __func__, __VA_ARGS__)
  148. #define NGLOG_CRITICAL(log_class, ...) \
  149. ::Log::FmtLogMessage(::Log::Class::log_class, ::Log::Level::Critical, __FILE__, __LINE__, \
  150. __func__, __VA_ARGS__)