|
|
|||
File indexing completed on 2026-03-29 07:58:15
0001 /* 0002 Open Asset Import Library (assimp) 0003 ---------------------------------------------------------------------- 0004 0005 Copyright (c) 2006-2025, assimp team 0006 0007 All rights reserved. 0008 0009 Redistribution and use of this software in source and binary forms, 0010 with or without modification, are permitted provided that the 0011 following conditions are met: 0012 0013 * Redistributions of source code must retain the above 0014 copyright notice, this list of conditions and the 0015 following disclaimer. 0016 0017 * Redistributions in binary form must reproduce the above 0018 copyright notice, this list of conditions and the 0019 following disclaimer in the documentation and/or other 0020 materials provided with the distribution. 0021 0022 * Neither the name of the assimp team, nor the names of its 0023 contributors may be used to endorse or promote products 0024 derived from this software without specific prior 0025 written permission of the assimp team. 0026 0027 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 0028 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 0029 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 0030 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 0031 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 0032 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 0033 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0034 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0035 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0036 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 0037 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0038 0039 ---------------------------------------------------------------------- 0040 */ 0041 0042 /** 0043 * @file DefaultLogger.hpp 0044 */ 0045 0046 #pragma once 0047 #ifndef INCLUDED_AI_DEFAULTLOGGER 0048 #define INCLUDED_AI_DEFAULTLOGGER 0049 0050 #ifdef __GNUC__ 0051 # pragma GCC system_header 0052 #endif 0053 0054 #include "LogStream.hpp" 0055 #include "Logger.hpp" 0056 #include "NullLogger.hpp" 0057 #include <vector> 0058 0059 #ifndef ASSIMP_BUILD_SINGLETHREADED 0060 #include <mutex> 0061 #include <thread> 0062 #endif 0063 0064 namespace Assimp { 0065 // ------------------------------------------------------------------------------------ 0066 class IOStream; 0067 struct LogStreamInfo; 0068 0069 /** default name of log-file */ 0070 #define ASSIMP_DEFAULT_LOG_NAME "AssimpLog.txt" 0071 0072 // ------------------------------------------------------------------------------------ 0073 /** @brief CPP-API: Primary logging facility of Assimp. 0074 * 0075 * The library stores its primary #Logger as a static member of this class. 0076 * #get() returns this primary logger. By default the underlying implementation is 0077 * just a #NullLogger which rejects all log messages. By calling #create(), logging 0078 * is turned on. To capture the log output multiple log streams (#LogStream) can be 0079 * attach to the logger. Some default streams for common streaming locations (such as 0080 * a file, std::cout, OutputDebugString()) are also provided. 0081 * 0082 * If you wish to customize the logging at an even deeper level supply your own 0083 * implementation of #Logger to #set(). 0084 * @note The whole logging stuff causes a small extra overhead for all imports. */ 0085 class ASSIMP_API DefaultLogger : public Logger { 0086 public: 0087 // ---------------------------------------------------------------------- 0088 /** @brief Creates a logging instance. 0089 * @param name Name for log file. Only valid in combination 0090 * with the aiDefaultLogStream_FILE flag. 0091 * @param severity Log severity, DEBUG turns on debug messages and VERBOSE turns on all messages. 0092 * @param defStreams Default log streams to be attached. Any bitwise 0093 * combination of the aiDefaultLogStream enumerated values. 0094 * If #aiDefaultLogStream_FILE is specified but an empty string is 0095 * passed for 'name', no log file is created at all. 0096 * @param io IOSystem to be used to open external files (such as the 0097 * log file). Pass nullptr to rely on the default implementation. 0098 * This replaces the default #NullLogger with a #DefaultLogger instance. */ 0099 static Logger *create(const char *name = ASSIMP_DEFAULT_LOG_NAME, 0100 LogSeverity severity = NORMAL, 0101 unsigned int defStreams = aiDefaultLogStream_DEBUGGER | aiDefaultLogStream_FILE, 0102 IOSystem *io = nullptr); 0103 0104 // ---------------------------------------------------------------------- 0105 /** @brief Setup a custom #Logger implementation. 0106 * 0107 * Use this if the provided #DefaultLogger class doesn't fit into 0108 * your needs. If the provided message formatting is OK for you, 0109 * it's much easier to use #create() and to attach your own custom 0110 * output streams to it. 0111 * Since set is intended to be used for custom loggers, the user is 0112 * responsible for instantiation and destruction (new / delete). 0113 * Before deletion of the custom logger, set(nullptr); must be called. 0114 * @param logger Pass NULL to setup a default NullLogger*/ 0115 static void set(Logger *logger); 0116 0117 // ---------------------------------------------------------------------- 0118 /** @brief Getter for singleton instance 0119 * @return Only instance. This is never null, but it could be a 0120 * NullLogger. Use isNullLogger to check this.*/ 0121 static Logger *get(); 0122 0123 // ---------------------------------------------------------------------- 0124 /** @brief Return whether a #NullLogger is currently active 0125 * @return true if the current logger is a #NullLogger. 0126 * Use create() or set() to setup a logger that does actually do 0127 * something else than just rejecting all log messages. */ 0128 static bool isNullLogger(); 0129 0130 // ---------------------------------------------------------------------- 0131 /** @brief Kills and deletes the current singleton logger and replaces 0132 * it with a #NullLogger instance. */ 0133 static void kill(); 0134 0135 // ---------------------------------------------------------------------- 0136 /** @copydoc Logger::attachStream */ 0137 bool attachStream(LogStream *pStream, unsigned int severity) override; 0138 0139 // ---------------------------------------------------------------------- 0140 /** @copydoc Logger::detachStream */ 0141 bool detachStream(LogStream *pStream, unsigned int severity) override; 0142 0143 private: 0144 // ---------------------------------------------------------------------- 0145 /** @briefPrivate construction for internal use by create(). 0146 * @param severity Logging granularity */ 0147 explicit DefaultLogger(LogSeverity severity); 0148 0149 // ---------------------------------------------------------------------- 0150 /** @briefDestructor */ 0151 ~DefaultLogger() override; 0152 0153 /** @brief Logs debug infos, only been written when severity level DEBUG or higher is set */ 0154 void OnDebug(const char *message) override; 0155 0156 /** @brief Logs debug infos, only been written when severity level VERBOSE is set */ 0157 void OnVerboseDebug(const char *message) override; 0158 0159 /** @brief Logs an info message */ 0160 void OnInfo(const char *message) override; 0161 0162 /** @brief Logs a warning message */ 0163 void OnWarn(const char *message) override; 0164 0165 /** @brief Logs an error message */ 0166 void OnError(const char *message) override; 0167 0168 // ---------------------------------------------------------------------- 0169 /** @brief Writes a message to all streams */ 0170 void WriteToStreams(const char *message, ErrorSeverity ErrorSev); 0171 0172 // ---------------------------------------------------------------------- 0173 /** @brief Returns the thread id. 0174 * @note This is an OS specific feature, if not supported, a 0175 * zero will be returned. 0176 */ 0177 unsigned int GetThreadID(); 0178 0179 private: 0180 // Aliases for stream container 0181 using StreamArray = std::vector<LogStreamInfo *>; 0182 using StreamIt = std::vector<LogStreamInfo *>::iterator; 0183 using ConstStreamIt = std::vector<LogStreamInfo *>::const_iterator; 0184 0185 //! only logging instance 0186 static Logger *m_pLogger; 0187 static NullLogger s_pNullLogger; 0188 0189 //! Attached streams 0190 StreamArray m_StreamArray; 0191 0192 #ifndef ASSIMP_BUILD_SINGLETHREADED 0193 std::mutex m_arrayMutex; 0194 #endif 0195 0196 bool noRepeatMsg; 0197 char lastMsg[MAX_LOG_MESSAGE_LENGTH * 2]; 0198 size_t lastLen; 0199 }; 0200 0201 // ------------------------------------------------------------------------------------ 0202 0203 } // Namespace Assimp 0204 0205 #endif // !! INCLUDED_AI_DEFAULTLOGGER
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|