vrshoot
diff libs/assimp/assimp/DefaultLogger.hpp @ 0:b2f14e535253
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 01 Feb 2014 19:58:19 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/assimp/assimp/DefaultLogger.hpp Sat Feb 01 19:58:19 2014 +0200 1.3 @@ -0,0 +1,190 @@ 1.4 +/* 1.5 +Open Asset Import Library (assimp) 1.6 +---------------------------------------------------------------------- 1.7 + 1.8 +Copyright (c) 2006-2012, assimp team 1.9 +All rights reserved. 1.10 + 1.11 +Redistribution and use of this software in source and binary forms, 1.12 +with or without modification, are permitted provided that the 1.13 +following conditions are met: 1.14 + 1.15 +* Redistributions of source code must retain the above 1.16 + copyright notice, this list of conditions and the 1.17 + following disclaimer. 1.18 + 1.19 +* Redistributions in binary form must reproduce the above 1.20 + copyright notice, this list of conditions and the 1.21 + following disclaimer in the documentation and/or other 1.22 + materials provided with the distribution. 1.23 + 1.24 +* Neither the name of the assimp team, nor the names of its 1.25 + contributors may be used to endorse or promote products 1.26 + derived from this software without specific prior 1.27 + written permission of the assimp team. 1.28 + 1.29 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.30 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.31 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.32 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.33 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.34 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.35 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.36 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.37 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.38 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.39 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.40 + 1.41 +---------------------------------------------------------------------- 1.42 +*/ 1.43 +/** @file DefaultLogger.h 1.44 +*/ 1.45 + 1.46 +#ifndef INCLUDED_AI_DEFAULTLOGGER 1.47 +#define INCLUDED_AI_DEFAULTLOGGER 1.48 + 1.49 +#include "Logger.hpp" 1.50 +#include "LogStream.hpp" 1.51 +#include "NullLogger.hpp" 1.52 +#include <vector> 1.53 + 1.54 +namespace Assimp { 1.55 +// ------------------------------------------------------------------------------------ 1.56 +class IOStream; 1.57 +struct LogStreamInfo; 1.58 + 1.59 +/** default name of logfile */ 1.60 +#define ASSIMP_DEFAULT_LOG_NAME "AssimpLog.txt" 1.61 + 1.62 +// ------------------------------------------------------------------------------------ 1.63 +/** @brief CPP-API: Primary logging facility of Assimp. 1.64 + * 1.65 + * The library stores its primary #Logger as a static member of this class. 1.66 + * #get() returns this primary logger. By default the underlying implementation is 1.67 + * just a #NullLogger which rejects all log messages. By calling #create(), logging 1.68 + * is turned on. To capture the log output multiple log streams (#LogStream) can be 1.69 + * attach to the logger. Some default streams for common streaming locations (such as 1.70 + * a file, std::cout, OutputDebugString()) are also provided. 1.71 + * 1.72 + * If you wish to customize the logging at an even deeper level supply your own 1.73 + * implementation of #Logger to #set(). 1.74 + * @note The whole logging stuff causes a small extra overhead for all imports. */ 1.75 +class ASSIMP_API DefaultLogger : 1.76 + public Logger { 1.77 + 1.78 +public: 1.79 + 1.80 + // ---------------------------------------------------------------------- 1.81 + /** @brief Creates a logging instance. 1.82 + * @param name Name for log file. Only valid in combination 1.83 + * with the aiDefaultLogStream_FILE flag. 1.84 + * @param severity Log severity, VERBOSE turns on debug messages 1.85 + * @param defStreams Default log streams to be attached. Any bitwise 1.86 + * combination of the aiDefaultLogStream enumerated values. 1.87 + * If #aiDefaultLogStream_FILE is specified but an empty string is 1.88 + * passed for 'name', no log file is created at all. 1.89 + * @param io IOSystem to be used to open external files (such as the 1.90 + * log file). Pass NULL to rely on the default implementation. 1.91 + * This replaces the default #NullLogger with a #DefaultLogger instance. */ 1.92 + static Logger *create(const char* name = ASSIMP_DEFAULT_LOG_NAME, 1.93 + LogSeverity severity = NORMAL, 1.94 + unsigned int defStreams = aiDefaultLogStream_DEBUGGER | aiDefaultLogStream_FILE, 1.95 + IOSystem* io = NULL); 1.96 + 1.97 + // ---------------------------------------------------------------------- 1.98 + /** @brief Setup a custom #Logger implementation. 1.99 + * 1.100 + * Use this if the provided #DefaultLogger class doesn't fit into 1.101 + * your needs. If the provided message formatting is OK for you, 1.102 + * it's much easier to use #create() and to attach your own custom 1.103 + * output streams to it. 1.104 + * @param logger Pass NULL to setup a default NullLogger*/ 1.105 + static void set (Logger *logger); 1.106 + 1.107 + // ---------------------------------------------------------------------- 1.108 + /** @brief Getter for singleton instance 1.109 + * @return Only instance. This is never null, but it could be a 1.110 + * NullLogger. Use isNullLogger to check this.*/ 1.111 + static Logger *get(); 1.112 + 1.113 + // ---------------------------------------------------------------------- 1.114 + /** @brief Return whether a #NullLogger is currently active 1.115 + * @return true if the current logger is a #NullLogger. 1.116 + * Use create() or set() to setup a logger that does actually do 1.117 + * something else than just rejecting all log messages. */ 1.118 + static bool isNullLogger(); 1.119 + 1.120 + // ---------------------------------------------------------------------- 1.121 + /** @brief Kills the current singleton logger and replaces it with a 1.122 + * #NullLogger instance. */ 1.123 + static void kill(); 1.124 + 1.125 + // ---------------------------------------------------------------------- 1.126 + /** @copydoc Logger::attachStream */ 1.127 + bool attachStream(LogStream *pStream, 1.128 + unsigned int severity); 1.129 + 1.130 + // ---------------------------------------------------------------------- 1.131 + /** @copydoc Logger::detatchStream */ 1.132 + bool detatchStream(LogStream *pStream, 1.133 + unsigned int severity); 1.134 + 1.135 + 1.136 +private: 1.137 + 1.138 + // ---------------------------------------------------------------------- 1.139 + /** @briefPrivate construction for internal use by create(). 1.140 + * @param severity Logging granularity */ 1.141 + DefaultLogger(LogSeverity severity); 1.142 + 1.143 + // ---------------------------------------------------------------------- 1.144 + /** @briefDestructor */ 1.145 + ~DefaultLogger(); 1.146 + 1.147 +private: 1.148 + 1.149 + /** @brief Logs debug infos, only been written when severity level VERBOSE is set */ 1.150 + void OnDebug(const char* message); 1.151 + 1.152 + /** @brief Logs an info message */ 1.153 + void OnInfo(const char* message); 1.154 + 1.155 + /** @brief Logs a warning message */ 1.156 + void OnWarn(const char* message); 1.157 + 1.158 + /** @brief Logs an error message */ 1.159 + void OnError(const char* message); 1.160 + 1.161 + // ---------------------------------------------------------------------- 1.162 + /** @brief Writes a message to all streams */ 1.163 + void WriteToStreams(const char* message, ErrorSeverity ErrorSev ); 1.164 + 1.165 + // ---------------------------------------------------------------------- 1.166 + /** @brief Returns the thread id. 1.167 + * @note This is an OS specific feature, if not supported, a 1.168 + * zero will be returned. 1.169 + */ 1.170 + unsigned int GetThreadID(); 1.171 + 1.172 +private: 1.173 + // Aliases for stream container 1.174 + typedef std::vector<LogStreamInfo*> StreamArray; 1.175 + typedef std::vector<LogStreamInfo*>::iterator StreamIt; 1.176 + typedef std::vector<LogStreamInfo*>::const_iterator ConstStreamIt; 1.177 + 1.178 + //! only logging instance 1.179 + static Logger *m_pLogger; 1.180 + static NullLogger s_pNullLogger; 1.181 + 1.182 + //! Attached streams 1.183 + StreamArray m_StreamArray; 1.184 + 1.185 + bool noRepeatMsg; 1.186 + char lastMsg[MAX_LOG_MESSAGE_LENGTH*2]; 1.187 + size_t lastLen; 1.188 +}; 1.189 +// ------------------------------------------------------------------------------------ 1.190 + 1.191 +} // Namespace Assimp 1.192 + 1.193 +#endif // !! INCLUDED_AI_DEFAULTLOGGER