log.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 <cassert>
  6. #include <chrono>
  7. #include <string>
  8. #include "common/common_types.h"
  9. namespace Log {
  10. /// Specifies the severity or level of detail of the log message.
  11. enum class Level : u8 {
  12. Trace, ///< Extremely detailed and repetitive debugging information that is likely to
  13. /// pollute logs.
  14. Debug, ///< Less detailed debugging information.
  15. Info, ///< Status information from important points during execution.
  16. Warning, ///< Minor or potential problems found during execution of a task.
  17. Error, ///< Major problems found during execution of a task that prevent it from being
  18. /// completed.
  19. Critical, ///< Major problems during execution that threathen the stability of the entire
  20. /// application.
  21. Count ///< Total number of logging levels
  22. };
  23. typedef u8 ClassType;
  24. /**
  25. * Specifies the sub-system that generated the log message.
  26. *
  27. * @note If you add a new entry here, also add a corresponding one to `ALL_LOG_CLASSES` in backend.cpp.
  28. */
  29. enum class Class : ClassType {
  30. Log, ///< Messages about the log system itself
  31. Common, ///< Library routines
  32. Common_Filesystem, ///< Filesystem interface library
  33. Common_Memory, ///< Memory mapping and management functions
  34. Core, ///< LLE emulation core
  35. Core_ARM11, ///< ARM11 CPU core
  36. Core_Timing, ///< CoreTiming functions
  37. Config, ///< Emulator configuration (including commandline)
  38. Debug, ///< Debugging tools
  39. Debug_Emulated, ///< Debug messages from the emulated programs
  40. Debug_GPU, ///< GPU debugging tools
  41. Debug_Breakpoint, ///< Logging breakpoints and watchpoints
  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_SRV, ///< The SRV (Service Directory) implementation
  47. Service_FS, ///< The FS (Filesystem) service implementation
  48. Service_ERR, ///< The ERR (Error) port implementation
  49. Service_APT, ///< The APT (Applets) service
  50. Service_GSP, ///< The GSP (GPU control) service
  51. Service_AC, ///< The AC (WiFi status) service
  52. Service_AM, ///< The AM (Application manager) service
  53. Service_PTM, ///< The PTM (Power status & misc.) service
  54. Service_LDR, ///< The LDR (3ds dll loader) service
  55. Service_NIM, ///< The NIM (Network interface manager) service
  56. Service_NWM, ///< The NWM (Network wlan manager) service
  57. Service_CFG, ///< The CFG (Configuration) service
  58. Service_DSP, ///< The DSP (DSP control) service
  59. Service_HID, ///< The HID (Human interface device) service
  60. Service_SOC, ///< The SOC (Socket) service
  61. Service_Y2R, ///< The Y2R (YUV to RGB conversion) service
  62. HW, ///< Low-level hardware emulation
  63. HW_Memory, ///< Memory-map and address translation
  64. HW_LCD, ///< LCD register emulation
  65. HW_GPU, ///< GPU control emulation
  66. Frontend, ///< Emulator UI
  67. Render, ///< Emulator video output and hardware acceleration
  68. Render_Software, ///< Software renderer backend
  69. Render_OpenGL, ///< OpenGL backend
  70. Loader, ///< ROM loader
  71. Count ///< Total number of logging classes
  72. };
  73. /// Logs a message to the global logger.
  74. void LogMessage(Class log_class, Level log_level,
  75. const char* filename, unsigned int line_nr, const char* function,
  76. #ifdef _MSC_VER
  77. _Printf_format_string_
  78. #endif
  79. const char* format, ...)
  80. #ifdef __GNUC__
  81. __attribute__((format(printf, 6, 7)))
  82. #endif
  83. ;
  84. } // namespace Log
  85. #define LOG_GENERIC(log_class, log_level, ...) \
  86. ::Log::LogMessage(::Log::Class::log_class, ::Log::Level::log_level, \
  87. __FILE__, __LINE__, __func__, __VA_ARGS__)
  88. #ifdef _DEBUG
  89. #define LOG_TRACE( log_class, ...) LOG_GENERIC(log_class, Trace, __VA_ARGS__)
  90. #else
  91. #define LOG_TRACE( log_class, ...) (void(0))
  92. #endif
  93. #define LOG_DEBUG( log_class, ...) LOG_GENERIC(log_class, Debug, __VA_ARGS__)
  94. #define LOG_INFO( log_class, ...) LOG_GENERIC(log_class, Info, __VA_ARGS__)
  95. #define LOG_WARNING( log_class, ...) LOG_GENERIC(log_class, Warning, __VA_ARGS__)
  96. #define LOG_ERROR( log_class, ...) LOG_GENERIC(log_class, Error, __VA_ARGS__)
  97. #define LOG_CRITICAL(log_class, ...) LOG_GENERIC(log_class, Critical, __VA_ARGS__)