GraphicsAPI_2020C
Logger.hpp
Go to the documentation of this file.
1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
4 
5 Copyright (c) 2006-2017, assimp team
6 
7 All rights reserved.
8 
9 Redistribution and use of this software in source and binary forms,
10 with or without modification, are permitted provided that the
11 following conditions are met:
12 
13 * Redistributions of source code must retain the above
14  copyright notice, this list of conditions and the
15  following disclaimer.
16 
17 * Redistributions in binary form must reproduce the above
18  copyright notice, this list of conditions and the
19  following disclaimer in the documentation and/or other
20  materials provided with the distribution.
21 
22 * Neither the name of the assimp team, nor the names of its
23  contributors may be used to endorse or promote products
24  derived from this software without specific prior
25  written permission of the assimp team.
26 
27 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 
39 ----------------------------------------------------------------------
40 */
41 
45 #ifndef INCLUDED_AI_LOGGER_H
46 #define INCLUDED_AI_LOGGER_H
47 
48 #include "types.h"
49 
50 namespace Assimp {
51 
52 class LogStream;
53 
54 // Maximum length of a log message. Longer messages are rejected.
55 #define MAX_LOG_MESSAGE_LENGTH 1024u
56 
57 // ----------------------------------------------------------------------------------
62 class ASSIMP_API Logger
63 #ifndef SWIG
64  : public Intern::AllocateFromAssimpHeap
65 #endif
66 {
67 public:
68 
69  // ----------------------------------------------------------------------
74  {
76  VERBOSE
77  };
78 
79  // ----------------------------------------------------------------------
88  {
89  Debugging = 1,
90  Info = 2,
91  Warn = 4,
92  Err = 8
93  };
94 
95 public:
96 
98  virtual ~Logger();
99 
100  // ----------------------------------------------------------------------
103  void debug(const char* message);
104  inline void debug(const std::string &message);
105 
106  // ----------------------------------------------------------------------
109  void info(const char* message);
110  inline void info(const std::string &message);
111 
112  // ----------------------------------------------------------------------
115  void warn(const char* message);
116  inline void warn(const std::string &message);
117 
118  // ----------------------------------------------------------------------
121  void error(const char* message);
122  inline void error(const std::string &message);
123 
124  // ----------------------------------------------------------------------
127  void setLogSeverity(LogSeverity log_severity);
128 
129  // ----------------------------------------------------------------------
131  LogSeverity getLogSeverity() const;
132 
133  // ----------------------------------------------------------------------
145  virtual bool attachStream(LogStream *pStream,
146  unsigned int severity = Debugging | Err | Warn | Info) = 0;
147 
148  // ----------------------------------------------------------------------
157  virtual bool detatchStream(LogStream *pStream,
158  unsigned int severity = Debugging | Err | Warn | Info) = 0;
159 
160 protected:
161 
163  Logger();
164 
166  explicit Logger(LogSeverity severity);
167 
168  // ----------------------------------------------------------------------
175  virtual void OnDebug(const char* message)= 0;
176 
177  // ----------------------------------------------------------------------
184  virtual void OnInfo(const char* message) = 0;
185 
186  // ----------------------------------------------------------------------
193  virtual void OnWarn(const char* essage) = 0;
194 
195  // ----------------------------------------------------------------------
202  virtual void OnError(const char* message) = 0;
203 
204 protected:
205 
208 };
209 
210 // ----------------------------------------------------------------------------------
211 // Default constructor
212 inline Logger::Logger() {
213  setLogSeverity(NORMAL);
214 }
215 
216 // ----------------------------------------------------------------------------------
217 // Virtual destructor
219 {
220 }
221 
222 // ----------------------------------------------------------------------------------
223 // Construction with given logging severity
224 inline Logger::Logger(LogSeverity severity) {
225  setLogSeverity(severity);
226 }
227 
228 // ----------------------------------------------------------------------------------
229 // Log severity setter
230 inline void Logger::setLogSeverity(LogSeverity log_severity){
231  m_Severity = log_severity;
232 }
233 
234 // ----------------------------------------------------------------------------------
235 // Log severity getter
237  return m_Severity;
238 }
239 
240 // ----------------------------------------------------------------------------------
241 inline void Logger::debug(const std::string &message)
242 {
243  return debug(message.c_str());
244 }
245 
246 // ----------------------------------------------------------------------------------
247 inline void Logger::error(const std::string &message)
248 {
249  return error(message.c_str());
250 }
251 
252 // ----------------------------------------------------------------------------------
253 inline void Logger::warn(const std::string &message)
254 {
255  return warn(message.c_str());
256 }
257 
258 // ----------------------------------------------------------------------------------
259 inline void Logger::info(const std::string &message)
260 {
261  return info(message.c_str());
262 }
263 
264 // ----------------------------------------------------------------------------------
265 
266 } // Namespace Assimp
267 
268 #endif // !! INCLUDED_AI_LOGGER_H
Basic data types and primitives, such as vectors or colors.
Assimp's CPP-API and all internal APIs.
Definition: DefaultIOStream.h:51
void debug(const char *message)
Writes a debug message.
ErrorSeverity
Description for severity of a log message.
Definition: Logger.hpp:87
void warn(const char *message)
Writes a warning message.
LogSeverity
Log severity to describe the granularity of logging.
Definition: Logger.hpp:73
CPP-API: Abstract interface for log stream implementations.
Definition: LogStream.hpp:60
Logger()
Default constructor.
Definition: Logger.hpp:212
Normal granularity of logging.
Definition: Logger.hpp:75
void error(const char *message)
Writes an error message.
virtual ~Logger()
Virtual destructor.
Definition: Logger.hpp:218
void info(const char *message)
Writes a info message.
LogSeverity m_Severity
Logger severity.
Definition: Logger.hpp:207
void setLogSeverity(LogSeverity log_severity)
Set a new log severity.
Definition: Logger.hpp:230
CPP-API: Abstract interface for logger implementations.
Definition: Logger.hpp:62
LogSeverity getLogSeverity() const
Get the current log severity.
Definition: Logger.hpp:236