Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

266 строки
9.4 KiB

  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2012, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. /** @file Logger.hpp
  34. * @brief Abstract base class 'Logger', base of the logging system.
  35. */
  36. #ifndef INCLUDED_AI_LOGGER_H
  37. #define INCLUDED_AI_LOGGER_H
  38. #include "types.h"
  39. namespace Assimp {
  40. class LogStream;
  41. // Maximum length of a log message. Longer messages are rejected.
  42. #define MAX_LOG_MESSAGE_LENGTH 1024u
  43. // ----------------------------------------------------------------------------------
  44. /** @brief CPP-API: Abstract interface for logger implementations.
  45. * Assimp provides a default implementation and uses it for almost all
  46. * logging stuff ('DefaultLogger'). This class defines just basic logging
  47. * behaviour and is not of interest for you. Instead, take a look at #DefaultLogger. */
  48. class ASSIMP_API Logger
  49. #ifndef SWIG
  50. : public Intern::AllocateFromAssimpHeap
  51. #endif
  52. {
  53. public:
  54. // ----------------------------------------------------------------------
  55. /** @enum LogSeverity
  56. * @brief Log severity to describe the granularity of logging.
  57. */
  58. enum LogSeverity
  59. {
  60. NORMAL, //!< Normal granularity of logging
  61. VERBOSE //!< Debug infos will be logged, too
  62. };
  63. // ----------------------------------------------------------------------
  64. /** @enum ErrorSeverity
  65. * @brief Description for severity of a log message.
  66. *
  67. * Every LogStream has a bitwise combination of these flags.
  68. * A LogStream doesn't receive any messages of a specific type
  69. * if it doesn't specify the corresponding ErrorSeverity flag.
  70. */
  71. enum ErrorSeverity
  72. {
  73. Debugging = 1, //!< Debug log message
  74. Info = 2, //!< Info log message
  75. Warn = 4, //!< Warn log message
  76. Err = 8 //!< Error log message
  77. };
  78. public:
  79. /** @brief Virtual destructor */
  80. virtual ~Logger();
  81. // ----------------------------------------------------------------------
  82. /** @brief Writes a debug message
  83. * @param message Debug message*/
  84. void debug(const char* message);
  85. inline void debug(const std::string &message);
  86. // ----------------------------------------------------------------------
  87. /** @brief Writes a info message
  88. * @param message Info message*/
  89. void info(const char* message);
  90. inline void info(const std::string &message);
  91. // ----------------------------------------------------------------------
  92. /** @brief Writes a warning message
  93. * @param message Warn message*/
  94. void warn(const char* message);
  95. inline void warn(const std::string &message);
  96. // ----------------------------------------------------------------------
  97. /** @brief Writes an error message
  98. * @param message Error message*/
  99. void error(const char* message);
  100. inline void error(const std::string &message);
  101. // ----------------------------------------------------------------------
  102. /** @brief Set a new log severity.
  103. * @param log_severity New severity for logging*/
  104. void setLogSeverity(LogSeverity log_severity);
  105. // ----------------------------------------------------------------------
  106. /** @brief Get the current log severity*/
  107. LogSeverity getLogSeverity() const;
  108. // ----------------------------------------------------------------------
  109. /** @brief Attach a new log-stream
  110. *
  111. * The logger takes ownership of the stream and is responsible
  112. * for its destruction (which is done using ::delete when the logger
  113. * itself is destroyed). Call detachStream to detach a stream and to
  114. * gain ownership of it again.
  115. * @param pStream Log-stream to attach
  116. * @param severity Message filter, specified which types of log
  117. * messages are dispatched to the stream. Provide a bitwise
  118. * combination of the ErrorSeverity flags.
  119. * @return true if the stream has been attached, false otherwise.*/
  120. virtual bool attachStream(LogStream *pStream,
  121. unsigned int severity = Debugging | Err | Warn | Info) = 0;
  122. // ----------------------------------------------------------------------
  123. /** @brief Detach a still attached stream from the logger (or
  124. * modify the filter flags bits)
  125. * @param pStream Log-stream instance for detaching
  126. * @param severity Provide a bitwise combination of the ErrorSeverity
  127. * flags. This value is &~ed with the current flags of the stream,
  128. * if the result is 0 the stream is detached from the Logger and
  129. * the caller retakes the possession of the stream.
  130. * @return true if the stream has been detached, false otherwise.*/
  131. virtual bool detatchStream(LogStream *pStream,
  132. unsigned int severity = Debugging | Err | Warn | Info) = 0;
  133. protected:
  134. /** Default constructor */
  135. Logger();
  136. /** Construction with a given log severity */
  137. Logger(LogSeverity severity);
  138. // ----------------------------------------------------------------------
  139. /** @brief Called as a request to write a specific debug message
  140. * @param message Debug message. Never longer than
  141. * MAX_LOG_MESSAGE_LENGTH characters (excluding the '0').
  142. * @note The message string is only valid until the scope of
  143. * the function is left.
  144. */
  145. virtual void OnDebug(const char* message)= 0;
  146. // ----------------------------------------------------------------------
  147. /** @brief Called as a request to write a specific info message
  148. * @param message Info message. Never longer than
  149. * MAX_LOG_MESSAGE_LENGTH characters (ecxluding the '0').
  150. * @note The message string is only valid until the scope of
  151. * the function is left.
  152. */
  153. virtual void OnInfo(const char* message) = 0;
  154. // ----------------------------------------------------------------------
  155. /** @brief Called as a request to write a specific warn message
  156. * @param message Warn message. Never longer than
  157. * MAX_LOG_MESSAGE_LENGTH characters (exluding the '0').
  158. * @note The message string is only valid until the scope of
  159. * the function is left.
  160. */
  161. virtual void OnWarn(const char* essage) = 0;
  162. // ----------------------------------------------------------------------
  163. /** @brief Called as a request to write a specific error message
  164. * @param message Error message. Never longer than
  165. * MAX_LOG_MESSAGE_LENGTH characters (exluding the '0').
  166. * @note The message string is only valid until the scope of
  167. * the function is left.
  168. */
  169. virtual void OnError(const char* message) = 0;
  170. protected:
  171. //! Logger severity
  172. LogSeverity m_Severity;
  173. };
  174. // ----------------------------------------------------------------------------------
  175. // Default constructor
  176. inline Logger::Logger() {
  177. setLogSeverity(NORMAL);
  178. }
  179. // ----------------------------------------------------------------------------------
  180. // Virtual destructor
  181. inline Logger::~Logger()
  182. {
  183. }
  184. // ----------------------------------------------------------------------------------
  185. // Construction with given logging severity
  186. inline Logger::Logger(LogSeverity severity) {
  187. setLogSeverity(severity);
  188. }
  189. // ----------------------------------------------------------------------------------
  190. // Log severity setter
  191. inline void Logger::setLogSeverity(LogSeverity log_severity){
  192. m_Severity = log_severity;
  193. }
  194. // ----------------------------------------------------------------------------------
  195. // Log severity getter
  196. inline Logger::LogSeverity Logger::getLogSeverity() const {
  197. return m_Severity;
  198. }
  199. // ----------------------------------------------------------------------------------
  200. inline void Logger::debug(const std::string &message)
  201. {
  202. return debug(message.c_str());
  203. }
  204. // ----------------------------------------------------------------------------------
  205. inline void Logger::error(const std::string &message)
  206. {
  207. return error(message.c_str());
  208. }
  209. // ----------------------------------------------------------------------------------
  210. inline void Logger::warn(const std::string &message)
  211. {
  212. return warn(message.c_str());
  213. }
  214. // ----------------------------------------------------------------------------------
  215. inline void Logger::info(const std::string &message)
  216. {
  217. return info(message.c_str());
  218. }
  219. // ----------------------------------------------------------------------------------
  220. } // Namespace Assimp
  221. #endif // !! INCLUDED_AI_LOGGER_H