log.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 "common/common_types.h"
  6. namespace Log {
  7. /// Specifies the severity or level of detail of the log message.
  8. enum class Level : u8 {
  9. Trace, ///< Extremely detailed and repetitive debugging information that is likely to
  10. /// pollute logs.
  11. Debug, ///< Less detailed debugging information.
  12. Info, ///< Status information from important points during execution.
  13. Warning, ///< Minor or potential problems found during execution of a task.
  14. Error, ///< Major problems found during execution of a task that prevent it from being
  15. /// completed.
  16. Critical, ///< Major problems during execution that threathen the stability of the entire
  17. /// application.
  18. Count ///< Total number of logging levels
  19. };
  20. typedef u8 ClassType;
  21. /**
  22. * Specifies the sub-system that generated the log message.
  23. *
  24. * @note If you add a new entry here, also add a corresponding one to `ALL_LOG_CLASSES` in
  25. * backend.cpp.
  26. */
  27. enum class Class : ClassType {
  28. Log, ///< Messages about the log system itself
  29. Common, ///< Library routines
  30. Common_Filesystem, ///< Filesystem interface library
  31. Common_Memory, ///< Memory mapping and management functions
  32. Core, ///< LLE emulation core
  33. Core_ARM, ///< ARM CPU core
  34. Core_Timing, ///< CoreTiming functions
  35. Config, ///< Emulator configuration (including commandline)
  36. Debug, ///< Debugging tools
  37. Debug_Emulated, ///< Debug messages from the emulated programs
  38. Debug_GPU, ///< GPU debugging tools
  39. Debug_Breakpoint, ///< Logging breakpoints and watchpoints
  40. Debug_GDBStub, ///< GDB Stub
  41. Kernel, ///< The HLE implementation of the CTR kernel
  42. Kernel_SVC, ///< Kernel system calls
  43. Service, ///< HLE implementation of system services. Each major service
  44. /// should have its own subclass.
  45. Service_ACC, ///< The ACC (Accounts) service
  46. Service_AM, ///< The AM (Applet manager) service
  47. Service_APM, ///< The APM (Performance) service
  48. Service_Audio, ///< The Audio (Audio control) service
  49. Service_FS, ///< The FS (Filesystem) service
  50. Service_HID, ///< The HID (Human interface device) service
  51. Service_LM, ///< The LM (Logger) service
  52. Service_NIFM, ///< The NIFM (Network interface) service
  53. Service_NVDRV, ///< The NVDRV (Nvidia driver) service
  54. Service_PCTL, ///< The PCTL (Parental control) service
  55. Service_SET, ///< The SET (Settings) service
  56. Service_SM, ///< The SM (Service manager) service
  57. Service_Time, ///< The time service
  58. Service_VI, ///< The VI (Video interface) service
  59. HW, ///< Low-level hardware emulation
  60. HW_Memory, ///< Memory-map and address translation
  61. HW_LCD, ///< LCD register emulation
  62. HW_GPU, ///< GPU control emulation
  63. HW_AES, ///< AES engine emulation
  64. IPC, ///< IPC interface
  65. Frontend, ///< Emulator UI
  66. Render, ///< Emulator video output and hardware acceleration
  67. Render_Software, ///< Software renderer backend
  68. Render_OpenGL, ///< OpenGL backend
  69. Audio, ///< Audio emulation
  70. Audio_DSP, ///< The HLE implementation of the DSP
  71. Audio_Sink, ///< Emulator audio output backend
  72. Loader, ///< ROM loader
  73. Input, ///< Input emulation
  74. Network, ///< Network emulation
  75. WebService, ///< Interface to Citra Web Services
  76. Count ///< Total number of logging classes
  77. };
  78. /// Logs a message to the global logger.
  79. void LogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_nr,
  80. const char* function,
  81. #ifdef _MSC_VER
  82. _Printf_format_string_
  83. #endif
  84. const char* format,
  85. ...)
  86. #ifdef __GNUC__
  87. __attribute__((format(printf, 6, 7)))
  88. #endif
  89. ;
  90. } // namespace Log
  91. #define LOG_GENERIC(log_class, log_level, ...) \
  92. ::Log::LogMessage(log_class, log_level, __FILE__, __LINE__, __func__, __VA_ARGS__)
  93. #ifdef _DEBUG
  94. #define LOG_TRACE(log_class, ...) \
  95. LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Trace, __VA_ARGS__)
  96. #else
  97. #define LOG_TRACE(log_class, ...) (void(0))
  98. #endif
  99. #define LOG_DEBUG(log_class, ...) \
  100. LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Debug, __VA_ARGS__)
  101. #define LOG_INFO(log_class, ...) \
  102. LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Info, __VA_ARGS__)
  103. #define LOG_WARNING(log_class, ...) \
  104. LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Warning, __VA_ARGS__)
  105. #define LOG_ERROR(log_class, ...) \
  106. LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Error, __VA_ARGS__)
  107. #define LOG_CRITICAL(log_class, ...) \
  108. LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Critical, __VA_ARGS__)