Logging.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #pragma once
  2. #include "App.h"
  3. #define SPDLOG_HEADER_ONLY
  4. #include <spdlog/spdlog.h>
  5. #define GP_LOG_TRACE SPDLOG_TRACE
  6. #define GP_LOG_DEBUG SPDLOG_DEBUG
  7. #define GP_LOG_INFO SPDLOG_INFO
  8. #define GP_LOG_WARN SPDLOG_WARN
  9. #define GP_LOG_ERROR SPDLOG_ERROR
  10. #define GP_LOG_CRITICAL SPDLOG_CRITICAL
  11. namespace gameplay
  12. {
  13. /**
  14. * Defines the system for managing and controlling logging output.
  15. *
  16. * Example:
  17. *
  18. * const int x = 9;
  19. *
  20. * GP_LOG_INFO("Hello Logger number: {}, x);
  21. *
  22. * To log message use:
  23. *
  24. * @see GP_LOG_TRACE()
  25. * @see GP_LOG_DEBUG()
  26. * @see GP_LOG_INFO()
  27. * @see GP_LOG_WARN()
  28. * @see GP_LOG_ERROR()
  29. * @see GP_LOG_CRITICAL()
  30. */
  31. class GP_API Logging
  32. {
  33. friend class App;
  34. public:
  35. enum class Level : uint32_t
  36. {
  37. LEVEL_TRACE,
  38. LEVEL_DEBUG,
  39. LEVEL_INFO,
  40. LEVEL_WARN,
  41. LEVEL_ERROR,
  42. LEVEL_CRITICAL,
  43. LEVEL_OFF
  44. };
  45. /**
  46. * Constructor.
  47. *
  48. * @see App::get_logging() instead.
  49. */
  50. Logging();
  51. /**
  52. * Destructor.
  53. */
  54. ~Logging();
  55. /**
  56. * Parses the logging level from a string.
  57. */
  58. static Logging::Level parse_level(const char* str);
  59. /**
  60. * Sets the current logging level.
  61. *
  62. * @param level The logging level to be set to.
  63. */
  64. void set_level(Level level);
  65. /**
  66. * Gets the current logging level.
  67. *
  68. * @return The current logging level.
  69. */
  70. Level get_level() const;
  71. private:
  72. void startup();
  73. void shutdown();
  74. };
  75. }