Path Tracer
Logger.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 */
42 
46 #ifndef INCLUDED_AI_LOGGER_H
47 #define INCLUDED_AI_LOGGER_H
48 
49 #include <assimp/types.h>
50 #include <assimp/TinyFormatter.h>
51 
52 namespace Assimp {
53 
54 class LogStream;
55 
56 // Maximum length of a log message. Longer messages are rejected.
57 #define MAX_LOG_MESSAGE_LENGTH 1024u
58 
59 // ----------------------------------------------------------------------------------
64 class ASSIMP_API Logger
65 #ifndef SWIG
66  : public Intern::AllocateFromAssimpHeap
67 #endif
68 {
69 public:
70 
71  // ----------------------------------------------------------------------
75  enum LogSeverity {
78  VERBOSE
79  };
80 
81  // ----------------------------------------------------------------------
90  Debugging = 1,
91  Info = 2,
92  Warn = 4,
93  Err = 8
94  };
95 
96 public:
97 
99  virtual ~Logger();
100 
101  // ----------------------------------------------------------------------
104  void debug(const char* message);
105  void debug(const std::string &message);
106 
107  // ----------------------------------------------------------------------
110  void verboseDebug(const char *message);
111  void verboseDebug(const std::string &message);
112 
113  // ----------------------------------------------------------------------
116  void info(const char* message);
117  void info(const std::string &message);
118 
119  // ----------------------------------------------------------------------
122  void warn(const char* message);
123  void warn(const std::string &message);
124 
125  // ----------------------------------------------------------------------
128  void error(const char* message);
129  void error(const std::string &message);
130 
131  // ----------------------------------------------------------------------
134  void setLogSeverity(LogSeverity log_severity);
135 
136  // ----------------------------------------------------------------------
138  LogSeverity getLogSeverity() const;
139 
140  // ----------------------------------------------------------------------
152  virtual bool attachStream(LogStream *pStream,
153  unsigned int severity = Debugging | Err | Warn | Info) = 0;
154 
155  // ----------------------------------------------------------------------
164  virtual bool detachStream(LogStream *pStream,
165  unsigned int severity = Debugging | Err | Warn | Info) = 0;
166 
167 protected:
171  Logger() AI_NO_EXCEPT;
172 
176  explicit Logger(LogSeverity severity);
177 
178  // ----------------------------------------------------------------------
186  virtual void OnDebug(const char* message)= 0;
187 
188  // ----------------------------------------------------------------------
196  virtual void OnVerboseDebug(const char *message) = 0;
197 
198  // ----------------------------------------------------------------------
206  virtual void OnInfo(const char* message) = 0;
207 
208  // ----------------------------------------------------------------------
216  virtual void OnWarn(const char* essage) = 0;
217 
218  // ----------------------------------------------------------------------
226  virtual void OnError(const char* message) = 0;
227 
228 protected:
229  LogSeverity m_Severity;
230 };
231 
232 // ----------------------------------------------------------------------------------
233 // Default constructor
234 inline
235 Logger::Logger() AI_NO_EXCEPT
236 : m_Severity(NORMAL) {
237  // empty
238 }
239 
240 // ----------------------------------------------------------------------------------
241 // Virtual destructor
242 inline
244  // empty
245 }
246 
247 // ----------------------------------------------------------------------------------
248 // Construction with given logging severity
249 inline
251 : m_Severity(severity) {
252  // empty
253 }
254 
255 // ----------------------------------------------------------------------------------
256 // Log severity setter
257 inline
259  m_Severity = log_severity;
260 }
261 
262 // ----------------------------------------------------------------------------------
263 // Log severity getter
264 inline
266  return m_Severity;
267 }
268 
269 // ----------------------------------------------------------------------------------
270 inline
271 void Logger::debug(const std::string &message) {
272  return debug(message.c_str());
273 }
274 
275 // ----------------------------------------------------------------------------------
276 inline void Logger::verboseDebug(const std::string &message) {
277  return verboseDebug(message.c_str());
278 }
279 
280 // ----------------------------------------------------------------------------------
281 inline
282 void Logger::error(const std::string &message) {
283  return error(message.c_str());
284 }
285 
286 // ----------------------------------------------------------------------------------
287 inline
288 void Logger::warn(const std::string &message) {
289  return warn(message.c_str());
290 }
291 
292 // ----------------------------------------------------------------------------------
293 inline
294 void Logger::info(const std::string &message) {
295  return info(message.c_str());
296 }
297 
298 } // Namespace Assimp
299 
300 // ------------------------------------------------------------------------------------------------
301 #define ASSIMP_LOG_WARN_F(string, ...) \
302  Assimp::DefaultLogger::get()->warn((Assimp::Formatter::format(string), __VA_ARGS__))
303 
304 #define ASSIMP_LOG_ERROR_F(string, ...) \
305  Assimp::DefaultLogger::get()->error((Assimp::Formatter::format(string), __VA_ARGS__))
306 
307 #define ASSIMP_LOG_DEBUG_F(string, ...) \
308  Assimp::DefaultLogger::get()->debug((Assimp::Formatter::format(string), __VA_ARGS__))
309 
310 #define ASSIMP_LOG_VERBOSE_DEBUG_F(string, ...) \
311  Assimp::DefaultLogger::get()->verboseDebug((Assimp::Formatter::format(string), __VA_ARGS__))
312 
313 #define ASSIMP_LOG_INFO_F(string, ...) \
314  Assimp::DefaultLogger::get()->info((Assimp::Formatter::format(string), __VA_ARGS__))
315 
316 #define ASSIMP_LOG_WARN(string) \
317  Assimp::DefaultLogger::get()->warn(string)
318 
319 #define ASSIMP_LOG_ERROR(string) \
320  Assimp::DefaultLogger::get()->error(string)
321 
322 #define ASSIMP_LOG_DEBUG(string) \
323  Assimp::DefaultLogger::get()->debug(string)
324 
325 #define ASSIMP_LOG_VERBOSE_DEBUG(string) \
326  Assimp::DefaultLogger::get()->verboseDebug(string)
327 
328 #define ASSIMP_LOG_INFO(string) \
329  Assimp::DefaultLogger::get()->info(string)
330 
331 #endif // !! INCLUDED_AI_LOGGER_H
Assimp::Logger::LogSeverity
LogSeverity
Log severity to describe the granularity of logging.
Definition: Logger.hpp:75
types.h
Assimp::Logger::Logger
Logger() AI_NO_EXCEPT
Definition: Logger.hpp:235
Assimp::Logger::ErrorSeverity
ErrorSeverity
Description for severity of a log message.
Definition: Logger.hpp:89
Assimp::Logger::info
void info(const char *message)
Writes a info message.
Assimp::Logger::detachStream
virtual bool detachStream(LogStream *pStream, unsigned int severity=Debugging|Err|Warn|Info)=0
Detach a still attached stream from the logger (or modify the filter flags bits)
Assimp::Logger
CPP-API: Abstract interface for logger implementations. Assimp provides a default implementation and ...
Definition: Logger.hpp:68
Assimp::Logger::DEBUG
@ DEBUG
Debug messages will be logged, but not verbose debug messages.
Definition: Logger.hpp:77
Assimp::Logger::debug
void debug(const char *message)
Writes a debug message.
Assimp::Logger::setLogSeverity
void setLogSeverity(LogSeverity log_severity)
Set a new log severity.
Definition: Logger.hpp:258
Assimp::Logger::NORMAL
@ NORMAL
Normal granularity of logging.
Definition: Logger.hpp:76
Assimp::LogStream
CPP-API: Abstract interface for log stream implementations.
Definition: LogStream.hpp:65
Assimp::Logger::warn
void warn(const char *message)
Writes a warning message.
Assimp::Logger::getLogSeverity
LogSeverity getLogSeverity() const
Get the current log severity.
Definition: Logger.hpp:265
Assimp::Logger::error
void error(const char *message)
Writes an error message.
Assimp::Logger::attachStream
virtual bool attachStream(LogStream *pStream, unsigned int severity=Debugging|Err|Warn|Info)=0
Attach a new log-stream.
Assimp::Logger::verboseDebug
void verboseDebug(const char *message)
Writes a debug message.
TinyFormatter.h
Utility to format log messages more easily. Introduced to get rid of the boost::format dependency....
Assimp
Definition: ai_assert.h:50
Assimp::Logger::~Logger
virtual ~Logger()
Virtual destructor.
Definition: Logger.hpp:243