Mercurial > hg > orthanc
comparison Core/Logging.h @ 3353:54cdad5a7228 emscripten-logging
Added a public function that will use emscripten-specific logging functions when using its SDK + scaffolding work. Build and UT OK on msvc15 x64. Not actually tested under *nix or emscripten yet
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 23 Apr 2019 21:40:57 +0200 |
parents | 4e43e67f8ecf |
children | 815b81142ff7 |
comparison
equal
deleted
inserted
replaced
3350:ba051f674f4b | 3353:54cdad5a7228 |
---|---|
79 | 79 |
80 void EnableInfoLevel(bool enabled); | 80 void EnableInfoLevel(bool enabled); |
81 | 81 |
82 void EnableTraceLevel(bool enabled); | 82 void EnableTraceLevel(bool enabled); |
83 | 83 |
84 #ifdef __EMSCRIPTEN__ | |
85 // calling this function will change the error_, warning_ and info_ | |
86 // stream objects so that their operator<< writes into the browser | |
87 // console using emscripten_console_error(), emscripten_console_warn() | |
88 // and emscripten_console_log() | |
89 void EnableEmscriptenLogging(); | |
90 #endif | |
91 | |
84 void SetTargetFile(const std::string& path); | 92 void SetTargetFile(const std::string& path); |
85 | 93 |
86 void SetTargetFolder(const std::string& path); | 94 void SetTargetFolder(const std::string& path); |
87 | 95 |
88 struct NullStream : public std::ostream | 96 struct NullStream : public std::ostream |
186 std::ostream& operator<< (const T& message) | 194 std::ostream& operator<< (const T& message) |
187 { | 195 { |
188 return (*stream_) << boost::lexical_cast<std::string>(message); | 196 return (*stream_) << boost::lexical_cast<std::string>(message); |
189 } | 197 } |
190 }; | 198 }; |
199 | |
200 /** | |
201 opaque pointer that represents the state of the logging configuration | |
202 */ | |
203 typedef void* LoggingMemento; | |
204 | |
205 /** | |
206 Returns an object that contains the logging configuration. | |
207 | |
208 This function allocates resources that you must dispose of by | |
209 using either RestoreLoggingMemento or DiscardLoggingMemento. | |
210 | |
211 This function is only to be used by tests. | |
212 */ | |
213 LoggingMemento CreateLoggingMemento(); | |
214 | |
215 /** | |
216 Restores the logging configuration. The logging system is restored in | |
217 the state it was in when the memento object was created through | |
218 GetLoggingMemento(). | |
219 | |
220 After calling this function, the memento object may not be used | |
221 again | |
222 | |
223 This function is only to be used by tests. | |
224 */ | |
225 void RestoreLoggingMemento(LoggingMemento memento); | |
226 | |
227 /** | |
228 Call this function if you do not plan on restoring the logging | |
229 configuration state that you captured with CreateLoggingMemento | |
230 | |
231 This function is only to be used by tests. | |
232 */ | |
233 void DiscardLoggingMemento(LoggingMemento memento); | |
234 | |
235 /** | |
236 std::streambuf subclass used in FunctionCallingStream | |
237 */ | |
238 template<typename T> | |
239 class FuncStreamBuf : public std::stringbuf | |
240 { | |
241 public: | |
242 FuncStreamBuf(T func) : func_(func) {} | |
243 | |
244 virtual int sync() | |
245 { | |
246 std::string text = this->str(); | |
247 const char* buf = text.c_str(); | |
248 func_(buf); | |
249 this->str(""); | |
250 return 0; | |
251 } | |
252 private: | |
253 T func_; | |
254 }; | |
255 | |
256 /** | |
257 Set custom logging streams for the error, warning and info logs. | |
258 This function may not be called if a log file or folder has been | |
259 set beforehand. All three pointers must be valid and cannot be NULL. | |
260 | |
261 Please ensure the supplied streams remain alive and valid as long as | |
262 logging calls are performed. | |
263 | |
264 In order to prevent dangling pointer usage, it is recommended to call | |
265 Orthanc::Logging::Reset() before the stream objects are destroyed and | |
266 the pointers become invalid. | |
267 */ | |
268 void SetErrorWarnInfoLoggingStreams(std::ostream* errorStream, | |
269 std::ostream* warningStream, | |
270 std::ostream* infoStream); | |
191 } | 271 } |
192 } | 272 } |
193 | 273 |
194 #endif // ORTHANC_ENABLE_LOGGING | 274 #endif // ORTHANC_ENABLE_LOGGING |