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