Logger.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #pragma once
  16. #include <OgreLogManager.h>
  17. #include <OgreString.h>
  18. #include <OgreStringConverter.h>
  19. #include <string>
  20. /**
  21. * Prints an error log message.
  22. *
  23. * @param message[in] Message to print.
  24. */
  25. #define LOG_ERROR(message) Ogre::LogManager::getSingleton().logMessage( \
  26. "[ERROR] " + Ogre::String(__FILE__) + " " \
  27. + Ogre::StringConverter::toString(__LINE__) + ": " + message, \
  28. Ogre::LML_CRITICAL \
  29. )
  30. /**
  31. * Prints awarning log message.
  32. *
  33. * @param message[in] Message to print.
  34. */
  35. #define LOG_WARNING(message) Ogre::LogManager::getSingleton().logMessage( \
  36. "[WARNING] " + Ogre::String(__FILE__) + " " \
  37. + Ogre::StringConverter::toString(__LINE__) + ": " + message, \
  38. Ogre::LML_NORMAL \
  39. )
  40. /**
  41. * Prints a trivial log message.
  42. *
  43. * @param message[in] Message to print.
  44. */
  45. #define LOG_TRIVIAL(message) Ogre::LogManager::getSingleton().logMessage( \
  46. message, Ogre::LML_TRIVIAL \
  47. )
  48. /**
  49. * Prints a log message to the console with normal priority.
  50. *
  51. * @param message[in] Message to print.
  52. */
  53. #define LOG_CONSOLE(message) Ogre::LogManager::getSingleton().logMessage( \
  54. message, Ogre::LML_NORMAL \
  55. )
  56. // TODO: Remove microsoft tools and leave only the generic?
  57. #ifdef _MSC_VER
  58. /**
  59. * Prints an explicit debug message to the log (Microsoft only).
  60. *
  61. * It includes the filename, line, and function name. The priority is critical
  62. *
  63. * @param message[in] Message to print.
  64. */
  65. #define LOG_DEBUG_EX(message) Ogre::LogManager::getSingleton().logMessage( \
  66. "[DEBUG] (" + __FILE__ + " " + Ogre::StringConverter::toString(__LINE__) \
  67. + ")(" + std::string(__FUNCTION__) + "): " + message, \
  68. Ogre::LML_CRITICAL \
  69. )
  70. /**
  71. * Prints a debug message to the log (Microsoft only).
  72. *
  73. * It includes the function name. The priority is critical
  74. *
  75. * @param message[in] Message to print.
  76. */
  77. #define LOG_DEBUG(message) Ogre::LogManager::getSingleton().logMessage(\
  78. "[DEBUG] (" + std::string(__FUNCTION__) + "): " + message, \
  79. Ogre::LML_CRITICAL \
  80. )
  81. #else
  82. /**
  83. * Prints an explicit debug message to the log.
  84. *
  85. * It includes the filename, line, and function name. The priority is critical
  86. *
  87. * @param message[in] Message to print.
  88. */
  89. #define LOG_DEBUG_EX(message) Ogre::LogManager::getSingleton().logMessage( \
  90. "[DEBUG] (" + __FILE__ + " " + Ogre::StringConverter::toString(__LINE__) \
  91. + ")(" + std::string(__PRETTY_FUNCTION__) + "): " + message, \
  92. Ogre::LML_CRITICAL \
  93. )
  94. /**
  95. * Prints a debug message to the log.
  96. *
  97. * It includes the function name. The priority is critical
  98. *
  99. * @param message[in] Message to print.
  100. */
  101. #define LOG_DEBUG(message) Ogre::LogManager::getSingleton().logMessage( \
  102. "[DEBUG] (" + std::string(__PRETTY_FUNCTION__) + "): " + message, \
  103. Ogre::LML_CRITICAL \
  104. )
  105. #endif