comparison OrthancFramework/Sources/Logging.h @ 5561:0b18690c1935

SDK: added OrthancPluginLogMessage to display plugin name + file and line from plugin
author Alain Mazy <am@orthanc.team>
date Tue, 23 Apr 2024 09:34:02 +0200
parents 48b8dae6dc77
children addccb1590d2
comparison
equal deleted inserted replaced
5560:c80dbbae3f60 5561:0b18690c1935
44 44
45 namespace Orthanc 45 namespace Orthanc
46 { 46 {
47 namespace Logging 47 namespace Logging
48 { 48 {
49 // Note: these values must match the ones in OrthancCPlugin.h
49 enum LogLevel 50 enum LogLevel
50 { 51 {
51 LogLevel_ERROR, 52 LogLevel_ERROR = 0,
52 LogLevel_WARNING, 53 LogLevel_WARNING = 1,
53 LogLevel_INFO, 54 LogLevel_INFO = 2,
54 LogLevel_TRACE 55 LogLevel_TRACE = 3
55 }; 56 };
56 57
57 /** 58 /**
58 * NB: The log level for each category is encoded as a bit 59 * NB: The log level for each category is encoded as a bit
59 * mask. As a consequence, there can be up to 31 log categories 60 * mask. As a consequence, there can be up to 31 log categories
60 * (not 32, as the value GENERIC is reserved for the log commands 61 * (not 32, as the value GENERIC is reserved for the log commands
61 * that don't fall in a specific category). 62 * that don't fall in a specific category).
63 * Note: these values must match the ones in OrthancCPlugin.h
62 **/ 64 **/
63 enum LogCategory 65 enum LogCategory
64 { 66 {
65 LogCategory_GENERIC = (1 << 0), 67 LogCategory_GENERIC = (1 << 0),
66 LogCategory_PLUGINS = (1 << 1), 68 LogCategory_PLUGINS = (1 << 1),
76 ORTHANC_PUBLIC LogLevel StringToLogLevel(const char* level); 78 ORTHANC_PUBLIC LogLevel StringToLogLevel(const char* level);
77 79
78 // "pluginContext" must be of type "OrthancPluginContext" 80 // "pluginContext" must be of type "OrthancPluginContext"
79 ORTHANC_PUBLIC void InitializePluginContext(void* pluginContext); 81 ORTHANC_PUBLIC void InitializePluginContext(void* pluginContext);
80 82
83 // note: this variant shall be called only from a plugin and only if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 12, 4) && ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 4)
84 ORTHANC_PUBLIC void InitializePluginContext(void* pluginContext, const char* pluginName);
85
81 ORTHANC_PUBLIC void Initialize(); 86 ORTHANC_PUBLIC void Initialize();
82 87
83 ORTHANC_PUBLIC void Finalize(); 88 ORTHANC_PUBLIC void Finalize();
84 89
85 ORTHANC_PUBLIC void Reset(); 90 ORTHANC_PUBLIC void Reset();
160 165
161 #if ORTHANC_ENABLE_LOGGING != 1 166 #if ORTHANC_ENABLE_LOGGING != 1
162 # define LOG(level) ::Orthanc::Logging::NullStream() 167 # define LOG(level) ::Orthanc::Logging::NullStream()
163 # define VLOG(unused) ::Orthanc::Logging::NullStream() 168 # define VLOG(unused) ::Orthanc::Logging::NullStream()
164 # define CLOG(level, category) ::Orthanc::Logging::NullStream() 169 # define CLOG(level, category) ::Orthanc::Logging::NullStream()
170 # define LOG_FROM_PLUGIN(level, category, pluginName, file, line) ::Orthanc::Logging::NullStream()
165 #else /* ORTHANC_ENABLE_LOGGING == 1 */ 171 #else /* ORTHANC_ENABLE_LOGGING == 1 */
166 172
167 #if !defined(__ORTHANC_FILE__) 173 #if !defined(__ORTHANC_FILE__)
168 # if defined(_MSC_VER) 174 # if defined(_MSC_VER)
169 # pragma message("Warning: Macro __ORTHANC_FILE__ is not defined, this will leak the full path of the source files in the binaries") 175 # pragma message("Warning: Macro __ORTHANC_FILE__ is not defined, this will leak the full path of the source files in the binaries")
180 (::Orthanc::Logging::LogLevel_TRACE, \ 186 (::Orthanc::Logging::LogLevel_TRACE, \
181 ::Orthanc::Logging::LogCategory_GENERIC, __ORTHANC_FILE__, __LINE__) 187 ::Orthanc::Logging::LogCategory_GENERIC, __ORTHANC_FILE__, __LINE__)
182 # define CLOG(level, category) ::Orthanc::Logging::InternalLogger \ 188 # define CLOG(level, category) ::Orthanc::Logging::InternalLogger \
183 (::Orthanc::Logging::LogLevel_ ## level, \ 189 (::Orthanc::Logging::LogLevel_ ## level, \
184 ::Orthanc::Logging::LogCategory_ ## category, __ORTHANC_FILE__, __LINE__) 190 ::Orthanc::Logging::LogCategory_ ## category, __ORTHANC_FILE__, __LINE__)
191 # define LOG_FROM_PLUGIN(level, category, pluginName, file, line) ::Orthanc::Logging::InternalLogger \
192 (level, category, pluginName, file, line)
185 #endif 193 #endif
186 194
187 195
188 196
189 #if (ORTHANC_ENABLE_LOGGING == 1 && \ 197 #if (ORTHANC_ENABLE_LOGGING == 1 && \
256 private: 264 private:
257 boost::mutex::scoped_lock lock_; 265 boost::mutex::scoped_lock lock_;
258 LogLevel level_; 266 LogLevel level_;
259 std::unique_ptr<std::stringstream> pluginStream_; 267 std::unique_ptr<std::stringstream> pluginStream_;
260 std::ostream* stream_; 268 std::ostream* stream_;
269 LogCategory category_;
270 const char* file_;
271 uint32_t line_;
261 272
262 void Setup(LogCategory category, 273 void Setup(LogCategory category,
274 const char* pluginName,
263 const char* file, 275 const char* file,
264 int line); 276 int line);
265 277
266 public: 278 public:
267 InternalLogger(LogLevel level, 279 InternalLogger(LogLevel level,
268 LogCategory category, 280 LogCategory category,
281 const char* file,
282 int line);
283
284 InternalLogger(LogLevel level,
285 LogCategory category,
286 const char* pluginName,
269 const char* file, 287 const char* file,
270 int line); 288 int line);
271 289
272 // For backward binary compatibility with Orthanc Framework <= 1.8.0 290 // For backward binary compatibility with Orthanc Framework <= 1.8.0
273 InternalLogger(LogLevel level, 291 InternalLogger(LogLevel level,