Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 09:30:08

0001 /*
0002 Open Asset Import Library (assimp)
0003 ----------------------------------------------------------------------
0004 
0005 Copyright (c) 2006-2024, 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 namespace Assimp {
0060 // ------------------------------------------------------------------------------------
0061 class IOStream;
0062 struct LogStreamInfo;
0063 
0064 /** default name of log-file */
0065 #define ASSIMP_DEFAULT_LOG_NAME "AssimpLog.txt"
0066 
0067 // ------------------------------------------------------------------------------------
0068 /** @brief CPP-API: Primary logging facility of Assimp.
0069  *
0070  *  The library stores its primary #Logger as a static member of this class.
0071  *  #get() returns this primary logger. By default the underlying implementation is
0072  *  just a #NullLogger which rejects all log messages. By calling #create(), logging
0073  *  is turned on. To capture the log output multiple log streams (#LogStream) can be
0074  *  attach to the logger. Some default streams for common streaming locations (such as
0075  *  a file, std::cout, OutputDebugString()) are also provided.
0076  *
0077  *  If you wish to customize the logging at an even deeper level supply your own
0078  *  implementation of #Logger to #set().
0079  *  @note The whole logging stuff causes a small extra overhead for all imports. */
0080 class ASSIMP_API DefaultLogger : public Logger {
0081 public:
0082     // ----------------------------------------------------------------------
0083     /** @brief Creates a logging instance.
0084      *  @param name Name for log file. Only valid in combination
0085      *    with the aiDefaultLogStream_FILE flag.
0086      *  @param severity Log severity, DEBUG turns on debug messages and VERBOSE turns on all messages.
0087      *  @param defStreams  Default log streams to be attached. Any bitwise
0088      *    combination of the aiDefaultLogStream enumerated values.
0089      *    If #aiDefaultLogStream_FILE is specified but an empty string is
0090      *    passed for 'name', no log file is created at all.
0091      *  @param  io IOSystem to be used to open external files (such as the
0092      *   log file). Pass nullptr to rely on the default implementation.
0093      *  This replaces the default #NullLogger with a #DefaultLogger instance. */
0094     static Logger *create(const char *name = ASSIMP_DEFAULT_LOG_NAME,
0095             LogSeverity severity = NORMAL,
0096             unsigned int defStreams = aiDefaultLogStream_DEBUGGER | aiDefaultLogStream_FILE,
0097             IOSystem *io = nullptr);
0098 
0099     // ----------------------------------------------------------------------
0100     /** @brief Setup a custom #Logger implementation.
0101      *
0102      *  Use this if the provided #DefaultLogger class doesn't fit into
0103      *  your needs. If the provided message formatting is OK for you,
0104      *  it's much easier to use #create() and to attach your own custom
0105      *  output streams to it.
0106      *  @param logger Pass NULL to setup a default NullLogger*/
0107     static void set(Logger *logger);
0108 
0109     // ----------------------------------------------------------------------
0110     /** @brief  Getter for singleton instance
0111      *   @return Only instance. This is never null, but it could be a
0112      *  NullLogger. Use isNullLogger to check this.*/
0113     static Logger *get();
0114 
0115     // ----------------------------------------------------------------------
0116     /** @brief  Return whether a #NullLogger is currently active
0117      *  @return true if the current logger is a #NullLogger.
0118      *  Use create() or set() to setup a logger that does actually do
0119      *  something else than just rejecting all log messages. */
0120     static bool isNullLogger();
0121 
0122     // ----------------------------------------------------------------------
0123     /** @brief  Kills the current singleton logger and replaces it with a
0124      *  #NullLogger instance. */
0125     static void kill();
0126 
0127     // ----------------------------------------------------------------------
0128     /** @copydoc Logger::attachStream   */
0129     bool attachStream(LogStream *pStream, unsigned int severity) override;
0130 
0131     // ----------------------------------------------------------------------
0132     /** @copydoc Logger::detachStream */
0133     bool detachStream(LogStream *pStream, unsigned int severity) override;
0134 
0135 private:
0136     // ----------------------------------------------------------------------
0137     /** @briefPrivate construction for internal use by create().
0138      *  @param severity Logging granularity  */
0139     explicit DefaultLogger(LogSeverity severity);
0140 
0141     // ----------------------------------------------------------------------
0142     /** @briefDestructor    */
0143     ~DefaultLogger() override;
0144 
0145     /** @brief  Logs debug infos, only been written when severity level DEBUG or higher is set */
0146     void OnDebug(const char *message) override;
0147 
0148     /** @brief  Logs debug infos, only been written when severity level VERBOSE is set */
0149     void OnVerboseDebug(const char *message) override;
0150 
0151     /** @brief  Logs an info message */
0152     void OnInfo(const char *message) override;
0153 
0154     /** @brief  Logs a warning message */
0155     void OnWarn(const char *message) override;
0156 
0157     /** @brief  Logs an error message */
0158     void OnError(const char *message) override;
0159 
0160     // ----------------------------------------------------------------------
0161     /** @brief Writes a message to all streams */
0162     void WriteToStreams(const char *message, ErrorSeverity ErrorSev);
0163 
0164     // ----------------------------------------------------------------------
0165     /** @brief Returns the thread id.
0166      *  @note This is an OS specific feature, if not supported, a
0167      *    zero will be returned.
0168      */
0169     unsigned int GetThreadID();
0170 
0171 private:
0172     //  Aliases for stream container
0173     using StreamArray = std::vector<LogStreamInfo *>;
0174     using StreamIt = std::vector<LogStreamInfo *>::iterator;
0175     using ConstStreamIt = std::vector<LogStreamInfo *>::const_iterator;
0176 
0177     //! only logging instance
0178     static Logger *m_pLogger;
0179     static NullLogger s_pNullLogger;
0180 
0181     //! Attached streams
0182     StreamArray m_StreamArray;
0183 
0184     bool noRepeatMsg;
0185     char lastMsg[MAX_LOG_MESSAGE_LENGTH * 2];
0186     size_t lastLen;
0187 };
0188 
0189 // ------------------------------------------------------------------------------------
0190 
0191 } // Namespace Assimp
0192 
0193 #endif // !! INCLUDED_AI_DEFAULTLOGGER