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