miniassimp

annotate 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
rev   line source
nuclear@0 1 /*
nuclear@0 2 Open Asset Import Library (assimp)
nuclear@0 3 ----------------------------------------------------------------------
nuclear@0 4
nuclear@0 5 Copyright (c) 2006-2018, assimp team
nuclear@0 6
nuclear@0 7
nuclear@0 8 All rights reserved.
nuclear@0 9
nuclear@0 10 Redistribution and use of this software in source and binary forms,
nuclear@0 11 with or without modification, are permitted provided that the
nuclear@0 12 following conditions are met:
nuclear@0 13
nuclear@0 14 * Redistributions of source code must retain the above
nuclear@0 15 copyright notice, this list of conditions and the
nuclear@0 16 following disclaimer.
nuclear@0 17
nuclear@0 18 * Redistributions in binary form must reproduce the above
nuclear@0 19 copyright notice, this list of conditions and the
nuclear@0 20 following disclaimer in the documentation and/or other
nuclear@0 21 materials provided with the distribution.
nuclear@0 22
nuclear@0 23 * Neither the name of the assimp team, nor the names of its
nuclear@0 24 contributors may be used to endorse or promote products
nuclear@0 25 derived from this software without specific prior
nuclear@0 26 written permission of the assimp team.
nuclear@0 27
nuclear@0 28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
nuclear@0 29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
nuclear@0 30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
nuclear@0 31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
nuclear@0 32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
nuclear@0 33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
nuclear@0 34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
nuclear@0 35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
nuclear@0 36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
nuclear@0 37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
nuclear@0 38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
nuclear@0 39
nuclear@0 40 ----------------------------------------------------------------------
nuclear@0 41 */
nuclear@0 42 /** @file DefaultLogger.hpp
nuclear@0 43 */
nuclear@0 44
nuclear@0 45 #ifndef INCLUDED_AI_DEFAULTLOGGER
nuclear@0 46 #define INCLUDED_AI_DEFAULTLOGGER
nuclear@0 47
nuclear@0 48 #include "Logger.hpp"
nuclear@0 49 #include "LogStream.hpp"
nuclear@0 50 #include "NullLogger.hpp"
nuclear@0 51 #include <vector>
nuclear@0 52
nuclear@0 53 namespace Assimp {
nuclear@0 54 // ------------------------------------------------------------------------------------
nuclear@0 55 class IOStream;
nuclear@0 56 struct LogStreamInfo;
nuclear@0 57
nuclear@0 58 /** default name of logfile */
nuclear@0 59 #define ASSIMP_DEFAULT_LOG_NAME "AssimpLog.txt"
nuclear@0 60
nuclear@0 61 // ------------------------------------------------------------------------------------
nuclear@0 62 /** @brief CPP-API: Primary logging facility of Assimp.
nuclear@0 63 *
nuclear@0 64 * The library stores its primary #Logger as a static member of this class.
nuclear@0 65 * #get() returns this primary logger. By default the underlying implementation is
nuclear@0 66 * just a #NullLogger which rejects all log messages. By calling #create(), logging
nuclear@0 67 * is turned on. To capture the log output multiple log streams (#LogStream) can be
nuclear@0 68 * attach to the logger. Some default streams for common streaming locations (such as
nuclear@0 69 * a file, std::cout, OutputDebugString()) are also provided.
nuclear@0 70 *
nuclear@0 71 * If you wish to customize the logging at an even deeper level supply your own
nuclear@0 72 * implementation of #Logger to #set().
nuclear@0 73 * @note The whole logging stuff causes a small extra overhead for all imports. */
nuclear@0 74 class ASSIMP_API DefaultLogger :
nuclear@0 75 public Logger {
nuclear@0 76
nuclear@0 77 public:
nuclear@0 78
nuclear@0 79 // ----------------------------------------------------------------------
nuclear@0 80 /** @brief Creates a logging instance.
nuclear@0 81 * @param name Name for log file. Only valid in combination
nuclear@0 82 * with the aiDefaultLogStream_FILE flag.
nuclear@0 83 * @param severity Log severity, VERBOSE turns on debug messages
nuclear@0 84 * @param defStreams Default log streams to be attached. Any bitwise
nuclear@0 85 * combination of the aiDefaultLogStream enumerated values.
nuclear@0 86 * If #aiDefaultLogStream_FILE is specified but an empty string is
nuclear@0 87 * passed for 'name', no log file is created at all.
nuclear@0 88 * @param io IOSystem to be used to open external files (such as the
nuclear@0 89 * log file). Pass NULL to rely on the default implementation.
nuclear@0 90 * This replaces the default #NullLogger with a #DefaultLogger instance. */
nuclear@0 91 static Logger *create(const char* name = ASSIMP_DEFAULT_LOG_NAME,
nuclear@0 92 LogSeverity severity = NORMAL,
nuclear@0 93 unsigned int defStreams = aiDefaultLogStream_DEBUGGER | aiDefaultLogStream_FILE,
nuclear@0 94 IOSystem* io = NULL);
nuclear@0 95
nuclear@0 96 // ----------------------------------------------------------------------
nuclear@0 97 /** @brief Setup a custom #Logger implementation.
nuclear@0 98 *
nuclear@0 99 * Use this if the provided #DefaultLogger class doesn't fit into
nuclear@0 100 * your needs. If the provided message formatting is OK for you,
nuclear@0 101 * it's much easier to use #create() and to attach your own custom
nuclear@0 102 * output streams to it.
nuclear@0 103 * @param logger Pass NULL to setup a default NullLogger*/
nuclear@0 104 static void set (Logger *logger);
nuclear@0 105
nuclear@0 106 // ----------------------------------------------------------------------
nuclear@0 107 /** @brief Getter for singleton instance
nuclear@0 108 * @return Only instance. This is never null, but it could be a
nuclear@0 109 * NullLogger. Use isNullLogger to check this.*/
nuclear@0 110 static Logger *get();
nuclear@0 111
nuclear@0 112 // ----------------------------------------------------------------------
nuclear@0 113 /** @brief Return whether a #NullLogger is currently active
nuclear@0 114 * @return true if the current logger is a #NullLogger.
nuclear@0 115 * Use create() or set() to setup a logger that does actually do
nuclear@0 116 * something else than just rejecting all log messages. */
nuclear@0 117 static bool isNullLogger();
nuclear@0 118
nuclear@0 119 // ----------------------------------------------------------------------
nuclear@0 120 /** @brief Kills the current singleton logger and replaces it with a
nuclear@0 121 * #NullLogger instance. */
nuclear@0 122 static void kill();
nuclear@0 123
nuclear@0 124 // ----------------------------------------------------------------------
nuclear@0 125 /** @copydoc Logger::attachStream */
nuclear@0 126 bool attachStream(LogStream *pStream,
nuclear@0 127 unsigned int severity);
nuclear@0 128
nuclear@0 129 // ----------------------------------------------------------------------
nuclear@0 130 /** @copydoc Logger::detatchStream */
nuclear@0 131 bool detatchStream(LogStream *pStream,
nuclear@0 132 unsigned int severity);
nuclear@0 133
nuclear@0 134 private:
nuclear@0 135 // ----------------------------------------------------------------------
nuclear@0 136 /** @briefPrivate construction for internal use by create().
nuclear@0 137 * @param severity Logging granularity */
nuclear@0 138 explicit DefaultLogger(LogSeverity severity);
nuclear@0 139
nuclear@0 140 // ----------------------------------------------------------------------
nuclear@0 141 /** @briefDestructor */
nuclear@0 142 ~DefaultLogger();
nuclear@0 143
nuclear@0 144 /** @brief Logs debug infos, only been written when severity level VERBOSE is set */
nuclear@0 145 void OnDebug(const char* message);
nuclear@0 146
nuclear@0 147 /** @brief Logs an info message */
nuclear@0 148 void OnInfo(const char* message);
nuclear@0 149
nuclear@0 150 /** @brief Logs a warning message */
nuclear@0 151 void OnWarn(const char* message);
nuclear@0 152
nuclear@0 153 /** @brief Logs an error message */
nuclear@0 154 void OnError(const char* message);
nuclear@0 155
nuclear@0 156 // ----------------------------------------------------------------------
nuclear@0 157 /** @brief Writes a message to all streams */
nuclear@0 158 void WriteToStreams(const char* message, ErrorSeverity ErrorSev );
nuclear@0 159
nuclear@0 160 // ----------------------------------------------------------------------
nuclear@0 161 /** @brief Returns the thread id.
nuclear@0 162 * @note This is an OS specific feature, if not supported, a
nuclear@0 163 * zero will be returned.
nuclear@0 164 */
nuclear@0 165 unsigned int GetThreadID();
nuclear@0 166
nuclear@0 167 private:
nuclear@0 168 // Aliases for stream container
nuclear@0 169 typedef std::vector<LogStreamInfo*> StreamArray;
nuclear@0 170 typedef std::vector<LogStreamInfo*>::iterator StreamIt;
nuclear@0 171 typedef std::vector<LogStreamInfo*>::const_iterator ConstStreamIt;
nuclear@0 172
nuclear@0 173 //! only logging instance
nuclear@0 174 static Logger *m_pLogger;
nuclear@0 175 static NullLogger s_pNullLogger;
nuclear@0 176
nuclear@0 177 //! Attached streams
nuclear@0 178 StreamArray m_StreamArray;
nuclear@0 179
nuclear@0 180 bool noRepeatMsg;
nuclear@0 181 char lastMsg[MAX_LOG_MESSAGE_LENGTH*2];
nuclear@0 182 size_t lastLen;
nuclear@0 183 };
nuclear@0 184 // ------------------------------------------------------------------------------------
nuclear@0 185
nuclear@0 186 } // Namespace Assimp
nuclear@0 187
nuclear@0 188 #endif // !! INCLUDED_AI_DEFAULTLOGGER