miniassimp
diff include/miniassimp/Logger.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/Logger.hpp Mon Jan 28 18:19:26 2019 +0200 1.3 @@ -0,0 +1,305 @@ 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 + 1.46 +/** @file Logger.hpp 1.47 + * @brief Abstract base class 'Logger', base of the logging system. 1.48 + */ 1.49 +#ifndef INCLUDED_AI_LOGGER_H 1.50 +#define INCLUDED_AI_LOGGER_H 1.51 + 1.52 +#include <miniassimp/types.h> 1.53 +#include <miniassimp/TinyFormatter.h> 1.54 + 1.55 +namespace Assimp { 1.56 + 1.57 +class LogStream; 1.58 + 1.59 +// Maximum length of a log message. Longer messages are rejected. 1.60 +#define MAX_LOG_MESSAGE_LENGTH 1024u 1.61 + 1.62 +// ---------------------------------------------------------------------------------- 1.63 +/** @brief CPP-API: Abstract interface for logger implementations. 1.64 + * Assimp provides a default implementation and uses it for almost all 1.65 + * logging stuff ('DefaultLogger'). This class defines just basic logging 1.66 + * behavior and is not of interest for you. Instead, take a look at #DefaultLogger. */ 1.67 +class ASSIMP_API Logger 1.68 +#ifndef SWIG 1.69 + : public Intern::AllocateFromAssimpHeap 1.70 +#endif 1.71 +{ 1.72 +public: 1.73 + 1.74 + // ---------------------------------------------------------------------- 1.75 + /** @enum LogSeverity 1.76 + * @brief Log severity to describe the granularity of logging. 1.77 + */ 1.78 + enum LogSeverity { 1.79 + NORMAL, //!< Normal granularity of logging 1.80 + VERBOSE //!< Debug infos will be logged, too 1.81 + }; 1.82 + 1.83 + // ---------------------------------------------------------------------- 1.84 + /** @enum ErrorSeverity 1.85 + * @brief Description for severity of a log message. 1.86 + * 1.87 + * Every LogStream has a bitwise combination of these flags. 1.88 + * A LogStream doesn't receive any messages of a specific type 1.89 + * if it doesn't specify the corresponding ErrorSeverity flag. 1.90 + */ 1.91 + enum ErrorSeverity { 1.92 + Debugging = 1, //!< Debug log message 1.93 + Info = 2, //!< Info log message 1.94 + Warn = 4, //!< Warn log message 1.95 + Err = 8 //!< Error log message 1.96 + }; 1.97 + 1.98 +public: 1.99 + 1.100 + /** @brief Virtual destructor */ 1.101 + virtual ~Logger(); 1.102 + 1.103 + // ---------------------------------------------------------------------- 1.104 + /** @brief Writes a debug message 1.105 + * @param message Debug message*/ 1.106 + void debug(const char* message); 1.107 + void debug(const std::string &message); 1.108 + 1.109 + // ---------------------------------------------------------------------- 1.110 + /** @brief Writes a info message 1.111 + * @param message Info message*/ 1.112 + void info(const char* message); 1.113 + void info(const std::string &message); 1.114 + 1.115 + // ---------------------------------------------------------------------- 1.116 + /** @brief Writes a warning message 1.117 + * @param message Warn message*/ 1.118 + void warn(const char* message); 1.119 + void warn(const std::string &message); 1.120 + 1.121 + // ---------------------------------------------------------------------- 1.122 + /** @brief Writes an error message 1.123 + * @param message Error message*/ 1.124 + void error(const char* message); 1.125 + void error(const std::string &message); 1.126 + 1.127 + // ---------------------------------------------------------------------- 1.128 + /** @brief Set a new log severity. 1.129 + * @param log_severity New severity for logging*/ 1.130 + void setLogSeverity(LogSeverity log_severity); 1.131 + 1.132 + // ---------------------------------------------------------------------- 1.133 + /** @brief Get the current log severity*/ 1.134 + LogSeverity getLogSeverity() const; 1.135 + 1.136 + // ---------------------------------------------------------------------- 1.137 + /** @brief Attach a new log-stream 1.138 + * 1.139 + * The logger takes ownership of the stream and is responsible 1.140 + * for its destruction (which is done using ::delete when the logger 1.141 + * itself is destroyed). Call detachStream to detach a stream and to 1.142 + * gain ownership of it again. 1.143 + * @param pStream Log-stream to attach 1.144 + * @param severity Message filter, specified which types of log 1.145 + * messages are dispatched to the stream. Provide a bitwise 1.146 + * combination of the ErrorSeverity flags. 1.147 + * @return true if the stream has been attached, false otherwise.*/ 1.148 + virtual bool attachStream(LogStream *pStream, 1.149 + unsigned int severity = Debugging | Err | Warn | Info) = 0; 1.150 + 1.151 + // ---------------------------------------------------------------------- 1.152 + /** @brief Detach a still attached stream from the logger (or 1.153 + * modify the filter flags bits) 1.154 + * @param pStream Log-stream instance for detaching 1.155 + * @param severity Provide a bitwise combination of the ErrorSeverity 1.156 + * flags. This value is &~ed with the current flags of the stream, 1.157 + * if the result is 0 the stream is detached from the Logger and 1.158 + * the caller retakes the possession of the stream. 1.159 + * @return true if the stream has been detached, false otherwise.*/ 1.160 + virtual bool detatchStream(LogStream *pStream, 1.161 + unsigned int severity = Debugging | Err | Warn | Info) = 0; 1.162 + 1.163 +protected: 1.164 + /** 1.165 + * Default constructor 1.166 + */ 1.167 + Logger() AI_NO_EXCEPT; 1.168 + 1.169 + /** 1.170 + * Construction with a given log severity 1.171 + */ 1.172 + explicit Logger(LogSeverity severity); 1.173 + 1.174 + // ---------------------------------------------------------------------- 1.175 + /** 1.176 + * @brief Called as a request to write a specific debug message 1.177 + * @param message Debug message. Never longer than 1.178 + * MAX_LOG_MESSAGE_LENGTH characters (excluding the '0'). 1.179 + * @note The message string is only valid until the scope of 1.180 + * the function is left. 1.181 + */ 1.182 + virtual void OnDebug(const char* message)= 0; 1.183 + 1.184 + // ---------------------------------------------------------------------- 1.185 + /** 1.186 + * @brief Called as a request to write a specific info message 1.187 + * @param message Info message. Never longer than 1.188 + * MAX_LOG_MESSAGE_LENGTH characters (ecxluding the '0'). 1.189 + * @note The message string is only valid until the scope of 1.190 + * the function is left. 1.191 + */ 1.192 + virtual void OnInfo(const char* message) = 0; 1.193 + 1.194 + // ---------------------------------------------------------------------- 1.195 + /** 1.196 + * @brief Called as a request to write a specific warn message 1.197 + * @param message Warn message. Never longer than 1.198 + * MAX_LOG_MESSAGE_LENGTH characters (exluding the '0'). 1.199 + * @note The message string is only valid until the scope of 1.200 + * the function is left. 1.201 + */ 1.202 + virtual void OnWarn(const char* essage) = 0; 1.203 + 1.204 + // ---------------------------------------------------------------------- 1.205 + /** 1.206 + * @brief Called as a request to write a specific error message 1.207 + * @param message Error message. Never longer than 1.208 + * MAX_LOG_MESSAGE_LENGTH characters (exluding the '0'). 1.209 + * @note The message string is only valid until the scope of 1.210 + * the function is left. 1.211 + */ 1.212 + virtual void OnError(const char* message) = 0; 1.213 + 1.214 +protected: 1.215 + LogSeverity m_Severity; 1.216 +}; 1.217 + 1.218 +// ---------------------------------------------------------------------------------- 1.219 +// Default constructor 1.220 +inline 1.221 +Logger::Logger() AI_NO_EXCEPT 1.222 +: m_Severity(NORMAL) { 1.223 + // empty 1.224 +} 1.225 + 1.226 +// ---------------------------------------------------------------------------------- 1.227 +// Virtual destructor 1.228 +inline 1.229 +Logger::~Logger() { 1.230 + // empty 1.231 +} 1.232 + 1.233 +// ---------------------------------------------------------------------------------- 1.234 +// Construction with given logging severity 1.235 +inline 1.236 +Logger::Logger(LogSeverity severity) 1.237 +: m_Severity(severity) { 1.238 + // empty 1.239 +} 1.240 + 1.241 +// ---------------------------------------------------------------------------------- 1.242 +// Log severity setter 1.243 +inline 1.244 +void Logger::setLogSeverity(LogSeverity log_severity){ 1.245 + m_Severity = log_severity; 1.246 +} 1.247 + 1.248 +// ---------------------------------------------------------------------------------- 1.249 +// Log severity getter 1.250 +inline 1.251 +Logger::LogSeverity Logger::getLogSeverity() const { 1.252 + return m_Severity; 1.253 +} 1.254 + 1.255 +// ---------------------------------------------------------------------------------- 1.256 +inline 1.257 +void Logger::debug(const std::string &message) { 1.258 + return debug(message.c_str()); 1.259 +} 1.260 + 1.261 +// ---------------------------------------------------------------------------------- 1.262 +inline 1.263 +void Logger::error(const std::string &message) { 1.264 + return error(message.c_str()); 1.265 +} 1.266 + 1.267 +// ---------------------------------------------------------------------------------- 1.268 +inline 1.269 +void Logger::warn(const std::string &message) { 1.270 + return warn(message.c_str()); 1.271 +} 1.272 + 1.273 +// ---------------------------------------------------------------------------------- 1.274 +inline 1.275 +void Logger::info(const std::string &message) { 1.276 + return info(message.c_str()); 1.277 +} 1.278 + 1.279 +// ------------------------------------------------------------------------------------------------ 1.280 +#define ASSIMP_LOG_WARN_F(string,...)\ 1.281 + DefaultLogger::get()->warn((Formatter::format(string),__VA_ARGS__)) 1.282 + 1.283 +#define ASSIMP_LOG_ERROR_F(string,...)\ 1.284 + DefaultLogger::get()->error((Formatter::format(string),__VA_ARGS__)) 1.285 + 1.286 +#define ASSIMP_LOG_DEBUG_F(string,...)\ 1.287 + DefaultLogger::get()->debug((Formatter::format(string),__VA_ARGS__)) 1.288 + 1.289 +#define ASSIMP_LOG_INFO_F(string,...)\ 1.290 + DefaultLogger::get()->info((Formatter::format(string),__VA_ARGS__)) 1.291 + 1.292 + 1.293 +#define ASSIMP_LOG_WARN(string)\ 1.294 + DefaultLogger::get()->warn(string) 1.295 + 1.296 +#define ASSIMP_LOG_ERROR(string)\ 1.297 + DefaultLogger::get()->error(string) 1.298 + 1.299 +#define ASSIMP_LOG_DEBUG(string)\ 1.300 + DefaultLogger::get()->debug(string) 1.301 + 1.302 +#define ASSIMP_LOG_INFO(string)\ 1.303 + DefaultLogger::get()->info(string) 1.304 + 1.305 + 1.306 +} // Namespace Assimp 1.307 + 1.308 +#endif // !! INCLUDED_AI_LOGGER_H