comparison Core/Logging.h @ 3992:f9863630ec7f

working on the shared library for Orthanc framework
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 05 Jun 2020 16:07:01 +0200
parents 94f4a18a79cc
children 7e8bfda62b43
comparison
equal deleted inserted replaced
3991:5d2348b39392 3992:f9863630ec7f
27 * General Public License for more details. 27 * General Public License for more details.
28 * 28 *
29 * You should have received a copy of the GNU General Public License 29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. 30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 **/ 31 **/
32
33
32 #pragma once 34 #pragma once
35
36 // To have ORTHANC_ENABLE_LOGGING defined if using the shared library
37 #include "OrthancFramework.h"
33 38
34 #include <iostream> 39 #include <iostream>
35 40
36 #if !defined(ORTHANC_ENABLE_LOGGING) 41 #if !defined(ORTHANC_ENABLE_LOGGING)
37 # error The macro ORTHANC_ENABLE_LOGGING must be defined 42 # error The macro ORTHANC_ENABLE_LOGGING must be defined
62 namespace Orthanc 67 namespace Orthanc
63 { 68 {
64 namespace Logging 69 namespace Logging
65 { 70 {
66 #if ORTHANC_ENABLE_LOGGING_PLUGIN == 1 71 #if ORTHANC_ENABLE_LOGGING_PLUGIN == 1
67 void Initialize(OrthancPluginContext* context); 72 void Initialize(OrthancPluginContext* context) ORTHANC_PUBLIC;
68 #else 73 #else
69 void Initialize(); 74 void Initialize() ORTHANC_PUBLIC;
70 #endif 75 #endif
71 76
72 void Finalize(); 77 void Finalize() ORTHANC_PUBLIC;
73 78
74 void Reset(); 79 void Reset() ORTHANC_PUBLIC;
75 80
76 void Flush(); 81 void Flush() ORTHANC_PUBLIC;
77 82
78 void EnableInfoLevel(bool enabled); 83 void EnableInfoLevel(bool enabled) ORTHANC_PUBLIC;
79 84
80 void EnableTraceLevel(bool enabled); 85 void EnableTraceLevel(bool enabled) ORTHANC_PUBLIC;
81 86
82 bool IsTraceLevelEnabled(); 87 bool IsTraceLevelEnabled() ORTHANC_PUBLIC;
83 88
84 bool IsInfoLevelEnabled(); 89 bool IsInfoLevelEnabled() ORTHANC_PUBLIC;
85 90
86 void SetTargetFile(const std::string& path); 91 void SetTargetFile(const std::string& path) ORTHANC_PUBLIC;
87 92
88 void SetTargetFolder(const std::string& path); 93 void SetTargetFolder(const std::string& path) ORTHANC_PUBLIC;
89 94
90 #if ORTHANC_ENABLE_LOGGING_STDIO == 1 95 #if ORTHANC_ENABLE_LOGGING_STDIO == 1
91 typedef void (*LoggingFunction)(const char*); 96 typedef void (*LoggingFunction)(const char*);
92 void SetErrorWarnInfoTraceLoggingFunctions( 97 void SetErrorWarnInfoTraceLoggingFunctions(
93 LoggingFunction errorLogFunc, 98 LoggingFunction errorLogFunc,
138 InternalLevel_WARNING, 143 InternalLevel_WARNING,
139 InternalLevel_INFO, 144 InternalLevel_INFO,
140 InternalLevel_TRACE 145 InternalLevel_TRACE
141 }; 146 };
142 147
143 class InternalLogger : public boost::noncopyable 148 class ORTHANC_PUBLIC InternalLogger : public boost::noncopyable
144 { 149 {
145 private: 150 private:
146 InternalLevel level_; 151 InternalLevel level_;
147 std::stringstream messageStream_; 152 std::stringstream messageStream_;
148 153
176 181
177 namespace Orthanc 182 namespace Orthanc
178 { 183 {
179 namespace Logging 184 namespace Logging
180 { 185 {
181 class InternalLogger 186 class ORTHANC_PUBLIC InternalLogger
182 { 187 {
183 private: 188 private:
184 boost::mutex::scoped_lock lock_; 189 boost::mutex::scoped_lock lock_;
185 NullStream null_; 190 NullStream null_;
186 std::ostream* stream_; 191 std::ostream* stream_;
210 This function allocates resources that you must dispose of by 215 This function allocates resources that you must dispose of by
211 using either RestoreLoggingMemento or DiscardLoggingMemento. 216 using either RestoreLoggingMemento or DiscardLoggingMemento.
212 217
213 This function is only to be used by tests. 218 This function is only to be used by tests.
214 */ 219 */
215 LoggingMemento CreateLoggingMemento(); 220 LoggingMemento CreateLoggingMemento() ORTHANC_PUBLIC;
216 221
217 /** 222 /**
218 Restores the logging configuration. The logging system is restored in 223 Restores the logging configuration. The logging system is restored in
219 the state it was in when the memento object was created through 224 the state it was in when the memento object was created through
220 GetLoggingMemento(). 225 GetLoggingMemento().
222 After calling this function, the memento object may not be used 227 After calling this function, the memento object may not be used
223 again 228 again
224 229
225 This function is only to be used by tests. 230 This function is only to be used by tests.
226 */ 231 */
227 void RestoreLoggingMemento(LoggingMemento memento); 232 void RestoreLoggingMemento(LoggingMemento memento) ORTHANC_PUBLIC;
228 233
229 /** 234 /**
230 Call this function if you do not plan on restoring the logging 235 Call this function if you do not plan on restoring the logging
231 configuration state that you captured with CreateLoggingMemento 236 configuration state that you captured with CreateLoggingMemento
232 237
233 This function is only to be used by tests. 238 This function is only to be used by tests.
234 */ 239 */
235 void DiscardLoggingMemento(LoggingMemento memento); 240 void DiscardLoggingMemento(LoggingMemento memento) ORTHANC_PUBLIC;
236 241
237 /** 242 /**
238 Set custom logging streams for the error, warning and info logs. 243 Set custom logging streams for the error, warning and info logs.
239 This function may not be called if a log file or folder has been 244 This function may not be called if a log file or folder has been
240 set beforehand. All three pointers must be valid and cannot be NULL. 245 set beforehand. All three pointers must be valid and cannot be NULL.
246 Orthanc::Logging::Reset() before the stream objects are destroyed and 251 Orthanc::Logging::Reset() before the stream objects are destroyed and
247 the pointers become invalid. 252 the pointers become invalid.
248 */ 253 */
249 void SetErrorWarnInfoLoggingStreams(std::ostream* errorStream, 254 void SetErrorWarnInfoLoggingStreams(std::ostream* errorStream,
250 std::ostream* warningStream, 255 std::ostream* warningStream,
251 std::ostream* infoStream); 256 std::ostream* infoStream) ORTHANC_PUBLIC;
252 257
253 #ifdef __EMSCRIPTEN__ 258 #ifdef __EMSCRIPTEN__
254 /** 259 /**
255 This function will change the logging streams so that the logging functions 260 This function will change the logging streams so that the logging functions
256 provided by emscripten html5.h API functions are used : it will change the 261 provided by emscripten html5.h API functions are used : it will change the
258 into the browser console using emscripten_console_error(), 263 into the browser console using emscripten_console_error(),
259 emscripten_console_warn() and emscripten_console_log(). This will allow for 264 emscripten_console_warn() and emscripten_console_log(). This will allow for
260 logging levels to be correctly handled by the browser when the code executes 265 logging levels to be correctly handled by the browser when the code executes
261 in Web Assembly 266 in Web Assembly
262 */ 267 */
263 void EnableEmscriptenLogging(); 268 void EnableEmscriptenLogging() ORTHANC_PUBLIC;
264 #endif 269 #endif
265 } 270 }
266 } 271 }
267 272
268 #endif // ORTHANC_ENABLE_LOGGING 273 #endif // ORTHANC_ENABLE_LOGGING