Logger.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // Created by wrede on 12.05.16.
  3. //
  4. #ifndef GBMOT_LOGGER_H
  5. #define GBMOT_LOGGER_H
  6. #include <string>
  7. namespace util
  8. {
  9. /**
  10. * Utility class for logging.
  11. * Is a singleton.
  12. * Provides three different types of messages.
  13. */
  14. class Logger
  15. {
  16. private:
  17. /**
  18. * -> Singleton
  19. */
  20. Logger();
  21. /**
  22. * True, if the info messages should be logged
  23. */
  24. bool info_;
  25. /**
  26. * True, if the debug messages should be logged
  27. */
  28. bool debug_;
  29. /**
  30. * Logs the given message.
  31. * @param message The message to log
  32. */
  33. void LogMessage(const std::string& message);
  34. /**
  35. * Logs the given error message.
  36. * @param message The error message to log
  37. */
  38. void LogErrorMessage(const std::string& message);
  39. public:
  40. /**
  41. * -> Singleton
  42. */
  43. Logger(Logger const&) = delete;
  44. /**
  45. * -> Singleton
  46. */
  47. void operator=(Logger const&) = delete;
  48. /**
  49. * Gets THE instance of this singleton.
  50. * Creates a new instance if not already created.
  51. */
  52. static Logger& Instance()
  53. {
  54. static Logger instance;
  55. return instance;
  56. }
  57. /**
  58. * Sets the debug message logging.
  59. * @param debug True, if the debug messages should be logged
  60. */
  61. static void SetDebug(bool debug);
  62. /**
  63. * Sets the info message logging.
  64. * @param info True, if the info messages should be logged
  65. */
  66. static void SetInfo(bool info);
  67. /**
  68. * If the debug messages are logged.
  69. * @return True, if the debug messages are logged
  70. */
  71. static bool IsDebugEnabled();
  72. /**
  73. * If the info messages are logged.
  74. * @return True, if the info messages are logged
  75. */
  76. static bool IsInfoEnabled();
  77. /**
  78. * Logs the given message as an info message.
  79. * @param message The info message to log
  80. */
  81. static void LogInfo(const std::string& message);
  82. /**
  83. * Logs the given message as an error message.
  84. * @param message The error message to log
  85. */
  86. static void LogError(const std::string& message);
  87. /**
  88. * Logs the given message as an debug message.
  89. * @param message The debug message to log
  90. */
  91. static void LogDebug(const std::string& message);
  92. };
  93. }
  94. #endif //GBMOT_LOGGER_H