/src/ogre/OgreMain/include/OgreLog.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | ----------------------------------------------------------------------------- |
3 | | This source file is part of OGRE |
4 | | (Object-oriented Graphics Rendering Engine) |
5 | | For the latest info, see http://www.ogre3d.org/ |
6 | | |
7 | | Copyright (c) 2000-2014 Torus Knot Software Ltd |
8 | | |
9 | | Permission is hereby granted, free of charge, to any person obtaining a copy |
10 | | of this software and associated documentation files (the "Software"), to deal |
11 | | in the Software without restriction, including without limitation the rights |
12 | | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
13 | | copies of the Software, and to permit persons to whom the Software is |
14 | | furnished to do so, subject to the following conditions: |
15 | | |
16 | | The above copyright notice and this permission notice shall be included in |
17 | | all copies or substantial portions of the Software. |
18 | | |
19 | | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
20 | | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
21 | | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
22 | | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
23 | | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
24 | | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
25 | | THE SOFTWARE. |
26 | | ----------------------------------------------------------------------------- |
27 | | */ |
28 | | |
29 | | #ifndef __Log_H__ |
30 | | #define __Log_H__ |
31 | | |
32 | | #include "OgrePrerequisites.h" |
33 | | #include "OgreCommon.h" |
34 | | #include "Threading/OgreThreadHeaders.h" |
35 | | #include "OgreHeaderPrefix.h" |
36 | | |
37 | | #include <fstream> |
38 | | #include <sstream> |
39 | | |
40 | | namespace Ogre { |
41 | | |
42 | | /** \addtogroup Core |
43 | | * @{ |
44 | | */ |
45 | | /** \addtogroup General |
46 | | * @{ |
47 | | */ |
48 | | |
49 | | /// @deprecated use LogMessageLevel instead |
50 | | enum LoggingLevel |
51 | | { |
52 | | LL_LOW = 1, |
53 | | LL_NORMAL = 2, |
54 | | LL_BOREME = 3 |
55 | | }; |
56 | | |
57 | | /** The importance of a logged message. |
58 | | */ |
59 | | enum LogMessageLevel |
60 | | { |
61 | | LML_TRIVIAL = 1, |
62 | | LML_NORMAL = 2, |
63 | | LML_WARNING = 3, |
64 | | LML_CRITICAL = 4 |
65 | | }; |
66 | | |
67 | | /** @remarks Pure Abstract class, derive this class and register to the Log to listen to log messages */ |
68 | | class LogListener |
69 | | { |
70 | | public: |
71 | 0 | virtual ~LogListener() {} |
72 | | |
73 | | /** |
74 | | |
75 | | This is called whenever the log receives a message and is about to write it out |
76 | | @param message |
77 | | The message to be logged |
78 | | @param lml |
79 | | The message level the log is using |
80 | | @param maskDebug |
81 | | If we are printing to the console or not |
82 | | @param logName |
83 | | The name of this log (so you can have several listeners for different logs, and identify them) |
84 | | @param skipThisMessage |
85 | | If set to true by the messageLogged() implementation message will not be logged |
86 | | */ |
87 | | virtual void messageLogged( const String& message, LogMessageLevel lml, bool maskDebug, const String &logName, bool& skipThisMessage ) = 0; |
88 | | }; |
89 | | |
90 | | |
91 | | /** |
92 | | Log class for writing debug/log data to files. |
93 | | |
94 | | You can control the default log level through the `OGRE_MIN_LOGLEVEL` environment variable. |
95 | | Here, the value 1 corresponds to #LML_TRIVIAL etc. |
96 | | @note Should not be used directly, but through the LogManager class. |
97 | | */ |
98 | | class _OgreExport Log : public LogAlloc |
99 | | { |
100 | | private: |
101 | | std::ofstream mLog; |
102 | | LogMessageLevel mLogLevel; |
103 | | bool mDebugOut; |
104 | | bool mSuppressFile; |
105 | | bool mTimeStamp; |
106 | | String mLogName; |
107 | | bool mTermHasColours; |
108 | | |
109 | | typedef std::vector<LogListener*> mtLogListener; |
110 | | mtLogListener mListeners; |
111 | | public: |
112 | | |
113 | | class Stream; |
114 | | |
115 | | OGRE_AUTO_MUTEX; // public to allow external locking |
116 | | /** |
117 | | |
118 | | Usual constructor - called by LogManager. |
119 | | */ |
120 | | Log( const String& name, bool debugOutput = true, bool suppressFileOutput = false); |
121 | | |
122 | | /** |
123 | | |
124 | | Default destructor. |
125 | | */ |
126 | | ~Log(); |
127 | | |
128 | | /// Return the name of the log |
129 | 0 | const String& getName() const { return mLogName; } |
130 | | /// Get whether debug output is enabled for this log |
131 | 0 | bool isDebugOutputEnabled() const { return mDebugOut; } |
132 | | /// Get whether file output is suppressed for this log |
133 | 0 | bool isFileOutputSuppressed() const { return mSuppressFile; } |
134 | | /// Get whether time stamps are printed for this log |
135 | 0 | bool isTimeStampEnabled() const { return mTimeStamp; } |
136 | | |
137 | | /** Log a message to the debugger and to log file (the default is |
138 | | "<code>OGRE.log</code>"), |
139 | | */ |
140 | | void logMessage( const String& message, LogMessageLevel lml = LML_NORMAL, bool maskDebug = false ); |
141 | | |
142 | | /** Get a stream object targeting this log. */ |
143 | | Stream stream(LogMessageLevel lml = LML_NORMAL, bool maskDebug = false); |
144 | | |
145 | | /** |
146 | | |
147 | | Enable or disable outputting log messages to the debugger. |
148 | | */ |
149 | | void setDebugOutputEnabled(bool debugOutput); |
150 | | /// @deprecated use setMinLogLevel() |
151 | | OGRE_DEPRECATED void setLogDetail(LoggingLevel ll); |
152 | | /// set the minimal #LogMessageLevel for a message to be logged |
153 | | void setMinLogLevel(LogMessageLevel lml); |
154 | | /** |
155 | | |
156 | | Enable or disable time stamps. |
157 | | */ |
158 | | void setTimeStampEnabled(bool timeStamp); |
159 | | /** Gets the level of the log detail. |
160 | | */ |
161 | 0 | LogMessageLevel getMinLogLevel() const { return mLogLevel; } |
162 | | /** |
163 | | |
164 | | Register a listener to this log |
165 | | @param listener |
166 | | A valid listener derived class |
167 | | */ |
168 | | void addListener(LogListener* listener); |
169 | | |
170 | | /** |
171 | | |
172 | | Unregister a listener from this log |
173 | | @param listener |
174 | | A valid listener derived class |
175 | | */ |
176 | | void removeListener(LogListener* listener); |
177 | | |
178 | | /** Stream object which targets a log. |
179 | | |
180 | | A stream logger object makes it simpler to send various things to |
181 | | a log. You can just use the operator<< implementation to stream |
182 | | anything to the log, which is cached until a Stream::Flush is |
183 | | encountered, or the stream itself is destroyed, at which point the |
184 | | cached contents are sent to the underlying log. You can use Log::stream() |
185 | | directly without assigning it to a local variable and as soon as the |
186 | | streaming is finished, the object will be destroyed and the message |
187 | | logged. |
188 | | @par |
189 | | You can stream control operations to this object too, such as |
190 | | std::setw() and std::setfill() to control formatting. |
191 | | @note |
192 | | Each Stream object is not thread safe, so do not pass it between |
193 | | threads. Multiple threads can hold their own Stream instances pointing |
194 | | at the same Log though and that is threadsafe. |
195 | | */ |
196 | | class _OgrePrivate Stream |
197 | | { |
198 | | private: |
199 | | Log* mTarget; |
200 | | LogMessageLevel mLevel; |
201 | | bool mMaskDebug; |
202 | | typedef StringStream BaseStream; |
203 | | BaseStream mCache; |
204 | | |
205 | | public: |
206 | | |
207 | | /// Simple type to indicate a flush of the stream to the log |
208 | | struct Flush {}; |
209 | | |
210 | | Stream(Log* target, LogMessageLevel lml, bool maskDebug) |
211 | | :mTarget(target), mLevel(lml), mMaskDebug(maskDebug) |
212 | 0 | { |
213 | 0 |
|
214 | 0 | } |
215 | | // move constructor |
216 | | Stream(Stream&& rhs) = default; |
217 | | |
218 | | ~Stream() |
219 | 0 | { |
220 | | // flush on destroy |
221 | 0 | if (mCache.tellp() > 0) |
222 | 0 | { |
223 | 0 | mTarget->logMessage(mCache.str(), mLevel, mMaskDebug); |
224 | 0 | } |
225 | 0 | } |
226 | | |
227 | | template <typename T> |
228 | | Stream& operator<< (const T& v) |
229 | 0 | { |
230 | 0 | mCache << v; |
231 | 0 | return *this; |
232 | 0 | } Unexecuted instantiation: Ogre::Log::Stream& Ogre::Log::Stream::operator<< <char [23]>(char const (&) [23]) Unexecuted instantiation: Ogre::Log::Stream& Ogre::Log::Stream::operator<< <unsigned short>(unsigned short const&) Unexecuted instantiation: Ogre::Log::Stream& Ogre::Log::Stream::operator<< <char [11]>(char const (&) [11]) Unexecuted instantiation: Ogre::Log::Stream& Ogre::Log::Stream::operator<< <char [12]>(char const (&) [12]) Unexecuted instantiation: Ogre::Log::Stream& Ogre::Log::Stream::operator<< <char [65]>(char const (&) [65]) Unexecuted instantiation: Ogre::Log::Stream& Ogre::Log::Stream::operator<< <char [37]>(char const (&) [37]) Unexecuted instantiation: Ogre::Log::Stream& Ogre::Log::Stream::operator<< <char [13]>(char const (&) [13]) Unexecuted instantiation: Ogre::Log::Stream& Ogre::Log::Stream::operator<< <char [9]>(char const (&) [9]) Unexecuted instantiation: Ogre::Log::Stream& Ogre::Log::Stream::operator<< <unsigned int>(unsigned int const&) Unexecuted instantiation: Ogre::Log::Stream& Ogre::Log::Stream::operator<< <char [38]>(char const (&) [38]) Unexecuted instantiation: Ogre::Log::Stream& Ogre::Log::Stream::operator<< <char [34]>(char const (&) [34]) Unexecuted instantiation: Ogre::Log::Stream& Ogre::Log::Stream::operator<< <char [39]>(char const (&) [39]) Unexecuted instantiation: Ogre::Log::Stream& Ogre::Log::Stream::operator<< <char [104]>(char const (&) [104]) Unexecuted instantiation: Ogre::Log::Stream& Ogre::Log::Stream::operator<< <long>(long const&) Unexecuted instantiation: Ogre::Log::Stream& Ogre::Log::Stream::operator<< <char [3]>(char const (&) [3]) Unexecuted instantiation: Ogre::Log::Stream& Ogre::Log::Stream::operator<< <char [19]>(char const (&) [19]) Unexecuted instantiation: Ogre::Log::Stream& Ogre::Log::Stream::operator<< <std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Unexecuted instantiation: Ogre::Log::Stream& Ogre::Log::Stream::operator<< <char [2]>(char const (&) [2]) Unexecuted instantiation: Ogre::Log::Stream& Ogre::Log::Stream::operator<< <char [41]>(char const (&) [41]) |
233 | | |
234 | | Stream& operator<< (const Flush& v) |
235 | 0 | { |
236 | 0 | (void)v; |
237 | 0 | mTarget->logMessage(mCache.str(), mLevel, mMaskDebug); |
238 | 0 | mCache.str(BLANKSTRING); |
239 | 0 | return *this; |
240 | 0 | } |
241 | | |
242 | | |
243 | | }; |
244 | | |
245 | | }; |
246 | | /** @} */ |
247 | | /** @} */ |
248 | | } |
249 | | |
250 | | #include "OgreHeaderSuffix.h" |
251 | | |
252 | | #endif |