Path Tracer
DefaultLogger.hpp
Go to the documentation of this file.
1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
4 
5 Copyright (c) 2006-2020, assimp team
6 
7 
8 All rights reserved.
9 
10 Redistribution and use of this software in source and binary forms,
11 with or without modification, are permitted provided that the
12 following conditions are met:
13 
14 * Redistributions of source code must retain the above
15  copyright notice, this list of conditions and the
16  following disclaimer.
17 
18 * Redistributions in binary form must reproduce the above
19  copyright notice, this list of conditions and the
20  following disclaimer in the documentation and/or other
21  materials provided with the distribution.
22 
23 * Neither the name of the assimp team, nor the names of its
24  contributors may be used to endorse or promote products
25  derived from this software without specific prior
26  written permission of the assimp team.
27 
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 
40 ----------------------------------------------------------------------
41 */
45 #ifndef INCLUDED_AI_DEFAULTLOGGER
46 #define INCLUDED_AI_DEFAULTLOGGER
47 
48 #include "LogStream.hpp"
49 #include "Logger.hpp"
50 #include "NullLogger.hpp"
51 #include <vector>
52 
53 namespace Assimp {
54 // ------------------------------------------------------------------------------------
55 class IOStream;
56 struct LogStreamInfo;
57 
59 #define ASSIMP_DEFAULT_LOG_NAME "AssimpLog.txt"
60 
61 // ------------------------------------------------------------------------------------
74 class ASSIMP_API DefaultLogger : public Logger {
75 
76 public:
77  // ----------------------------------------------------------------------
89  static Logger *create(const char *name = ASSIMP_DEFAULT_LOG_NAME,
90  LogSeverity severity = NORMAL,
91  unsigned int defStreams = aiDefaultLogStream_DEBUGGER | aiDefaultLogStream_FILE,
92  IOSystem *io = nullptr);
93 
94  // ----------------------------------------------------------------------
102  static void set(Logger *logger);
103 
104  // ----------------------------------------------------------------------
108  static Logger *get();
109 
110  // ----------------------------------------------------------------------
115  static bool isNullLogger();
116 
117  // ----------------------------------------------------------------------
120  static void kill();
121 
122  // ----------------------------------------------------------------------
124  bool attachStream(LogStream *pStream,
125  unsigned int severity);
126 
127  // ----------------------------------------------------------------------
129  bool detachStream(LogStream *pStream,
130  unsigned int severity);
131 
132 private:
133  // ----------------------------------------------------------------------
136  explicit DefaultLogger(LogSeverity severity);
137 
138  // ----------------------------------------------------------------------
140  ~DefaultLogger();
141 
143  void OnDebug(const char *message);
144 
146  void OnVerboseDebug(const char *message);
147 
149  void OnInfo(const char *message);
150 
152  void OnWarn(const char *message);
153 
155  void OnError(const char *message);
156 
157  // ----------------------------------------------------------------------
159  void WriteToStreams(const char *message, ErrorSeverity ErrorSev);
160 
161  // ----------------------------------------------------------------------
166  unsigned int GetThreadID();
167 
168 private:
169  // Aliases for stream container
170  typedef std::vector<LogStreamInfo *> StreamArray;
171  typedef std::vector<LogStreamInfo *>::iterator StreamIt;
172  typedef std::vector<LogStreamInfo *>::const_iterator ConstStreamIt;
173 
175  static Logger *m_pLogger;
176  static NullLogger s_pNullLogger;
177 
179  StreamArray m_StreamArray;
180 
181  bool noRepeatMsg;
182  char lastMsg[MAX_LOG_MESSAGE_LENGTH * 2];
183  size_t lastLen;
184 };
185 // ------------------------------------------------------------------------------------
186 
187 } // Namespace Assimp
188 
189 #endif // !! INCLUDED_AI_DEFAULTLOGGER
Assimp::NullLogger
CPP-API: Empty logging implementation.
Definition: NullLogger.hpp:60
ASSIMP_DEFAULT_LOG_NAME
#define ASSIMP_DEFAULT_LOG_NAME
Definition: DefaultLogger.hpp:59
Assimp::Logger::LogSeverity
LogSeverity
Log severity to describe the granularity of logging.
Definition: Logger.hpp:75
aiDefaultLogStream_DEBUGGER
@ aiDefaultLogStream_DEBUGGER
Definition: types.h:462
Assimp::DefaultLogger::detachStream
bool detachStream(LogStream *pStream, unsigned int severity)
Detach a still attached stream from the logger (or modify the filter flags bits)
aiDefaultLogStream_FILE
@ aiDefaultLogStream_FILE
Definition: types.h:451
Assimp::Logger::ErrorSeverity
ErrorSeverity
Description for severity of a log message.
Definition: Logger.hpp:89
LogStream.hpp
Abstract base class 'LogStream', representing an output log stream.
Assimp::Logger
CPP-API: Abstract interface for logger implementations. Assimp provides a default implementation and ...
Definition: Logger.hpp:68
NullLogger.hpp
Dummy logger.
Assimp::DefaultLogger::kill
static void kill()
Kills the current singleton logger and replaces it with a #NullLogger instance.
Assimp::LogStream
CPP-API: Abstract interface for log stream implementations.
Definition: LogStream.hpp:65
Assimp::DefaultLogger::attachStream
bool attachStream(LogStream *pStream, unsigned int severity)
Attach a new log-stream.
Logger.hpp
Abstract base class 'Logger', base of the logging system.
Assimp::DefaultLogger::isNullLogger
static bool isNullLogger()
Return whether a #NullLogger is currently active.
Assimp::DefaultLogger::create
static Logger * create(const char *name=ASSIMP_DEFAULT_LOG_NAME, LogSeverity severity=NORMAL, unsigned int defStreams=aiDefaultLogStream_DEBUGGER|aiDefaultLogStream_FILE, IOSystem *io=nullptr)
Creates a logging instance.
Assimp::DefaultLogger::get
static Logger * get()
Getter for singleton instance.
Assimp::IOSystem
CPP-API: Interface to the file system.
Definition: IOSystem.hpp:93
Assimp::DefaultLogger
CPP-API: Primary logging facility of Assimp.
Definition: DefaultLogger.hpp:74
Assimp
Definition: ai_assert.h:50
Assimp::DefaultLogger::set
static void set(Logger *logger)
Setup a custom Logger implementation.