DefaultLogger.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. Open Asset Import Library (ASSIMP)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2008, ASSIMP Development 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 Development 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. #if (!defined AI_DEFAULTLOGGER_H_INCLUDED)
  34. #define AI_DEFAULTLOGGER_H_INCLUDED
  35. #include "Logger.h"
  36. #include "NullLogger.h"
  37. #include <vector>
  38. namespace Assimp
  39. {
  40. // ---------------------------------------------------------------------------
  41. class IOStream;
  42. struct LogStreamInfo;
  43. // ---------------------------------------------------------------------------
  44. /** @class DefaultLogger
  45. * @brief Default logging implementation. The logger writes into a file.
  46. * The name can be set by creating the logger. If no filename was specified
  47. * the logger will use the standard out and error streams.
  48. */
  49. class ASSIMP_API DefaultLogger :
  50. public Logger
  51. {
  52. public:
  53. /** @brief Creates a custom logging instance (DefaultLogger)
  54. * @param name Name for logfile
  55. * @param severity Log severity, VERBOSE will activate debug messages
  56. *
  57. * This replaces the default NullLogger with a DefaultLogger instance.
  58. */
  59. static Logger *create(const std::string &name, LogSeverity severity);
  60. /** @brief Setup a custom implementation of the Logger interface as
  61. * default logger.
  62. *
  63. * Use this if the provided DefaultLogger class doesn't fit into
  64. * your needs. If the provided message formatting is OK for you,
  65. * it is easier to use create() to create a DefaultLogger and to attach
  66. * your own custom output streams to it than using this method.
  67. * @param logger Pass NULL to setup a default NullLogger
  68. */
  69. static void set (Logger *logger);
  70. /** @brief Getter for singleton instance
  71. * @return Only instance. This is never null, but it could be a
  72. * NullLogger. Use isNullLogger to check this.
  73. */
  74. static Logger *get();
  75. /** @brief Return whether a default NullLogger is currently active
  76. * @return true if the current logger id a NullLogger.
  77. * Use create() or set() to setup a custom logger.
  78. */
  79. static bool isNullLogger();
  80. /** @brief Will kill the singleton instance and setup a NullLogger as
  81. logger */
  82. static void kill();
  83. /** @brief Logs debug infos, only been written when severity level VERBOSE is set */
  84. void debug(const std::string &message);
  85. /** @brief Logs an info message */
  86. void info(const std::string &message);
  87. /** @brief Logs a warning message */
  88. void warn(const std::string &message);
  89. /** @brief Logs an error message */
  90. void error(const std::string &message);
  91. /** @drief Severity setter */
  92. void setLogSeverity(LogSeverity log_severity);
  93. /** @brief Detach a still attached stream from logger */
  94. void attachStream(LogStream *pStream, unsigned int severity);
  95. /** @brief Detach a still attached stream from logger */
  96. void detatchStream(LogStream *pStream, unsigned int severity);
  97. private:
  98. /** @brief Constructor
  99. * @param name Name for logfile, keep this empty to use std::cout and std::cerr
  100. * @param severity Severity of logger
  101. */
  102. DefaultLogger(const std::string &name, LogSeverity severity);
  103. /** @brief Destructor */
  104. ~DefaultLogger();
  105. /** @brief Writes message into a file */
  106. void writeToStreams(const std::string &message, ErrorSeverity ErrorSev );
  107. /** @brief Returns the thread id.
  108. * @remark This is an OS specific feature, if not supported, a zero will be returned.
  109. */
  110. std::string getThreadID();
  111. private:
  112. // Aliases for stream container
  113. typedef std::vector<LogStreamInfo*> StreamArray;
  114. typedef std::vector<LogStreamInfo*>::iterator StreamIt;
  115. typedef std::vector<LogStreamInfo*>::const_iterator ConstStreamIt;
  116. //! only logging instance
  117. static Logger *m_pLogger;
  118. static NullLogger s_pNullLogger;
  119. //! Logger severity
  120. LogSeverity m_Severity;
  121. //! Attached streams
  122. StreamArray m_StreamArray;
  123. //! Array with default streams
  124. std::vector<LogStream*> m_Streams;
  125. bool noRepeatMsg;
  126. std::string lastMsg;
  127. };
  128. // ---------------------------------------------------------------------------
  129. } // Namespace Assimp
  130. #endif // !! AI_DEFAULTLOGGER_H_INCLUDED