1/*
2Open Asset Import Library (assimp)
3----------------------------------------------------------------------
4
5Copyright (c) 2006-2017, assimp team
6
7All rights reserved.
8
9Redistribution and use of this software in source and binary forms,
10with or without modification, are permitted provided that the
11following 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
27THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
39----------------------------------------------------------------------
40*/
41
42/** @file Logger.hpp
43 * @brief Abstract base class 'Logger', base of the logging system.
44 */
45#ifndef INCLUDED_AI_LOGGER_H
46#define INCLUDED_AI_LOGGER_H
47
48#include "types.h"
49
50namespace Assimp {
51
52class LogStream;
53
54// Maximum length of a log message. Longer messages are rejected.
55#define MAX_LOG_MESSAGE_LENGTH 1024u
56
57// ----------------------------------------------------------------------------------
58/** @brief CPP-API: Abstract interface for logger implementations.
59 * Assimp provides a default implementation and uses it for almost all
60 * logging stuff ('DefaultLogger'). This class defines just basic logging
61 * behaviour and is not of interest for you. Instead, take a look at #DefaultLogger. */
62class ASSIMP_API Logger
63#ifndef SWIG
64 : public Intern::AllocateFromAssimpHeap
65#endif
66{
67public:
68
69 // ----------------------------------------------------------------------
70 /** @enum LogSeverity
71 * @brief Log severity to describe the granularity of logging.
72 */
73 enum LogSeverity
74 {
75 NORMAL, //!< Normal granularity of logging
76 VERBOSE //!< Debug infos will be logged, too
77 };
78
79 // ----------------------------------------------------------------------
80 /** @enum ErrorSeverity
81 * @brief Description for severity of a log message.
82 *
83 * Every LogStream has a bitwise combination of these flags.
84 * A LogStream doesn't receive any messages of a specific type
85 * if it doesn't specify the corresponding ErrorSeverity flag.
86 */
87 enum ErrorSeverity
88 {
89 Debugging = 1, //!< Debug log message
90 Info = 2, //!< Info log message
91 Warn = 4, //!< Warn log message
92 Err = 8 //!< Error log message
93 };
94
95public:
96
97 /** @brief Virtual destructor */
98 virtual ~Logger();
99
100 // ----------------------------------------------------------------------
101 /** @brief Writes a debug message
102 * @param message Debug message*/
103 void debug(const char* message);
104 inline void debug(const std::string &message);
105
106 // ----------------------------------------------------------------------
107 /** @brief Writes a info message
108 * @param message Info message*/
109 void info(const char* message);
110 inline void info(const std::string &message);
111
112 // ----------------------------------------------------------------------
113 /** @brief Writes a warning message
114 * @param message Warn message*/
115 void warn(const char* message);
116 inline void warn(const std::string &message);
117
118 // ----------------------------------------------------------------------
119 /** @brief Writes an error message
120 * @param message Error message*/
121 void error(const char* message);
122 inline void error(const std::string &message);
123
124 // ----------------------------------------------------------------------
125 /** @brief Set a new log severity.
126 * @param log_severity New severity for logging*/
127 void setLogSeverity(LogSeverity log_severity);
128
129 // ----------------------------------------------------------------------
130 /** @brief Get the current log severity*/
131 LogSeverity getLogSeverity() const;
132
133 // ----------------------------------------------------------------------
134 /** @brief Attach a new log-stream
135 *
136 * The logger takes ownership of the stream and is responsible
137 * for its destruction (which is done using ::delete when the logger
138 * itself is destroyed). Call detachStream to detach a stream and to
139 * gain ownership of it again.
140 * @param pStream Log-stream to attach
141 * @param severity Message filter, specified which types of log
142 * messages are dispatched to the stream. Provide a bitwise
143 * combination of the ErrorSeverity flags.
144 * @return true if the stream has been attached, false otherwise.*/
145 virtual bool attachStream(LogStream *pStream,
146 unsigned int severity = Debugging | Err | Warn | Info) = 0;
147
148 // ----------------------------------------------------------------------
149 /** @brief Detach a still attached stream from the logger (or
150 * modify the filter flags bits)
151 * @param pStream Log-stream instance for detaching
152 * @param severity Provide a bitwise combination of the ErrorSeverity
153 * flags. This value is &~ed with the current flags of the stream,
154 * if the result is 0 the stream is detached from the Logger and
155 * the caller retakes the possession of the stream.
156 * @return true if the stream has been detached, false otherwise.*/
157 virtual bool detatchStream(LogStream *pStream,
158 unsigned int severity = Debugging | Err | Warn | Info) = 0;
159
160protected:
161
162 /** Default constructor */
163 Logger();
164
165 /** Construction with a given log severity */
166 explicit Logger(LogSeverity severity);
167
168 // ----------------------------------------------------------------------
169 /** @brief Called as a request to write a specific debug message
170 * @param message Debug message. Never longer than
171 * MAX_LOG_MESSAGE_LENGTH characters (excluding the '0').
172 * @note The message string is only valid until the scope of
173 * the function is left.
174 */
175 virtual void OnDebug(const char* message)= 0;
176
177 // ----------------------------------------------------------------------
178 /** @brief Called as a request to write a specific info message
179 * @param message Info message. Never longer than
180 * MAX_LOG_MESSAGE_LENGTH characters (ecxluding the '0').
181 * @note The message string is only valid until the scope of
182 * the function is left.
183 */
184 virtual void OnInfo(const char* message) = 0;
185
186 // ----------------------------------------------------------------------
187 /** @brief Called as a request to write a specific warn message
188 * @param message Warn message. Never longer than
189 * MAX_LOG_MESSAGE_LENGTH characters (exluding the '0').
190 * @note The message string is only valid until the scope of
191 * the function is left.
192 */
193 virtual void OnWarn(const char* essage) = 0;
194
195 // ----------------------------------------------------------------------
196 /** @brief Called as a request to write a specific error message
197 * @param message Error message. Never longer than
198 * MAX_LOG_MESSAGE_LENGTH characters (exluding the '0').
199 * @note The message string is only valid until the scope of
200 * the function is left.
201 */
202 virtual void OnError(const char* message) = 0;
203
204protected:
205
206 //! Logger severity
207 LogSeverity m_Severity;
208};
209
210// ----------------------------------------------------------------------------------
211// Default constructor
212inline Logger::Logger() {
213 setLogSeverity(NORMAL);
214}
215
216// ----------------------------------------------------------------------------------
217// Virtual destructor
218inline Logger::~Logger()
219{
220}
221
222// ----------------------------------------------------------------------------------
223// Construction with given logging severity
224inline Logger::Logger(LogSeverity severity) {
225 setLogSeverity(severity);
226}
227
228// ----------------------------------------------------------------------------------
229// Log severity setter
230inline void Logger::setLogSeverity(LogSeverity log_severity){
231 m_Severity = log_severity;
232}
233
234// ----------------------------------------------------------------------------------
235// Log severity getter
236inline Logger::LogSeverity Logger::getLogSeverity() const {
237 return m_Severity;
238}
239
240// ----------------------------------------------------------------------------------
241inline void Logger::debug(const std::string &message)
242{
243 return debug(message.c_str());
244}
245
246// ----------------------------------------------------------------------------------
247inline void Logger::error(const std::string &message)
248{
249 return error(message.c_str());
250}
251
252// ----------------------------------------------------------------------------------
253inline void Logger::warn(const std::string &message)
254{
255 return warn(message.c_str());
256}
257
258// ----------------------------------------------------------------------------------
259inline 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
269