Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

191 Zeilen
7.2 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 DefaultLogger.h
  34. */
  35. #ifndef INCLUDED_AI_DEFAULTLOGGER
  36. #define INCLUDED_AI_DEFAULTLOGGER
  37. #include "Logger.hpp"
  38. #include "LogStream.hpp"
  39. #include "NullLogger.hpp"
  40. #include <vector>
  41. namespace Assimp {
  42. // ------------------------------------------------------------------------------------
  43. class IOStream;
  44. struct LogStreamInfo;
  45. /** default name of logfile */
  46. #define ASSIMP_DEFAULT_LOG_NAME "AssimpLog.txt"
  47. // ------------------------------------------------------------------------------------
  48. /** @brief CPP-API: Primary logging facility of Assimp.
  49. *
  50. * The library stores its primary #Logger as a static member of this class.
  51. * #get() returns this primary logger. By default the underlying implementation is
  52. * just a #NullLogger which rejects all log messages. By calling #create(), logging
  53. * is turned on. To capture the log output multiple log streams (#LogStream) can be
  54. * attach to the logger. Some default streams for common streaming locations (such as
  55. * a file, std::cout, OutputDebugString()) are also provided.
  56. *
  57. * If you wish to customize the logging at an even deeper level supply your own
  58. * implementation of #Logger to #set().
  59. * @note The whole logging stuff causes a small extra overhead for all imports. */
  60. class ASSIMP_API DefaultLogger :
  61. public Logger {
  62. public:
  63. // ----------------------------------------------------------------------
  64. /** @brief Creates a logging instance.
  65. * @param name Name for log file. Only valid in combination
  66. * with the aiDefaultLogStream_FILE flag.
  67. * @param severity Log severity, VERBOSE turns on debug messages
  68. * @param defStreams Default log streams to be attached. Any bitwise
  69. * combination of the aiDefaultLogStream enumerated values.
  70. * If #aiDefaultLogStream_FILE is specified but an empty string is
  71. * passed for 'name', no log file is created at all.
  72. * @param io IOSystem to be used to open external files (such as the
  73. * log file). Pass NULL to rely on the default implementation.
  74. * This replaces the default #NullLogger with a #DefaultLogger instance. */
  75. static Logger *create(const char* name = ASSIMP_DEFAULT_LOG_NAME,
  76. LogSeverity severity = NORMAL,
  77. unsigned int defStreams = aiDefaultLogStream_DEBUGGER | aiDefaultLogStream_FILE,
  78. IOSystem* io = NULL);
  79. // ----------------------------------------------------------------------
  80. /** @brief Setup a custom #Logger implementation.
  81. *
  82. * Use this if the provided #DefaultLogger class doesn't fit into
  83. * your needs. If the provided message formatting is OK for you,
  84. * it's much easier to use #create() and to attach your own custom
  85. * output streams to it.
  86. * @param logger Pass NULL to setup a default NullLogger*/
  87. static void set (Logger *logger);
  88. // ----------------------------------------------------------------------
  89. /** @brief Getter for singleton instance
  90. * @return Only instance. This is never null, but it could be a
  91. * NullLogger. Use isNullLogger to check this.*/
  92. static Logger *get();
  93. // ----------------------------------------------------------------------
  94. /** @brief Return whether a #NullLogger is currently active
  95. * @return true if the current logger is a #NullLogger.
  96. * Use create() or set() to setup a logger that does actually do
  97. * something else than just rejecting all log messages. */
  98. static bool isNullLogger();
  99. // ----------------------------------------------------------------------
  100. /** @brief Kills the current singleton logger and replaces it with a
  101. * #NullLogger instance. */
  102. static void kill();
  103. // ----------------------------------------------------------------------
  104. /** @copydoc Logger::attachStream */
  105. bool attachStream(LogStream *pStream,
  106. unsigned int severity);
  107. // ----------------------------------------------------------------------
  108. /** @copydoc Logger::detatchStream */
  109. bool detatchStream(LogStream *pStream,
  110. unsigned int severity);
  111. private:
  112. // ----------------------------------------------------------------------
  113. /** @briefPrivate construction for internal use by create().
  114. * @param severity Logging granularity */
  115. DefaultLogger(LogSeverity severity);
  116. // ----------------------------------------------------------------------
  117. /** @briefDestructor */
  118. ~DefaultLogger();
  119. private:
  120. /** @brief Logs debug infos, only been written when severity level VERBOSE is set */
  121. void OnDebug(const char* message);
  122. /** @brief Logs an info message */
  123. void OnInfo(const char* message);
  124. /** @brief Logs a warning message */
  125. void OnWarn(const char* message);
  126. /** @brief Logs an error message */
  127. void OnError(const char* message);
  128. // ----------------------------------------------------------------------
  129. /** @brief Writes a message to all streams */
  130. void WriteToStreams(const char* message, ErrorSeverity ErrorSev );
  131. // ----------------------------------------------------------------------
  132. /** @brief Returns the thread id.
  133. * @note This is an OS specific feature, if not supported, a
  134. * zero will be returned.
  135. */
  136. unsigned int GetThreadID();
  137. private:
  138. // Aliases for stream container
  139. typedef std::vector<LogStreamInfo*> StreamArray;
  140. typedef std::vector<LogStreamInfo*>::iterator StreamIt;
  141. typedef std::vector<LogStreamInfo*>::const_iterator ConstStreamIt;
  142. //! only logging instance
  143. static Logger *m_pLogger;
  144. static NullLogger s_pNullLogger;
  145. //! Attached streams
  146. StreamArray m_StreamArray;
  147. bool noRepeatMsg;
  148. char lastMsg[MAX_LOG_MESSAGE_LENGTH*2];
  149. size_t lastLen;
  150. };
  151. // ------------------------------------------------------------------------------------
  152. } // Namespace Assimp
  153. #endif // !! INCLUDED_AI_DEFAULTLOGGER