comparison OrthancFramework/Sources/Logging.h @ 4268:0ae2ca210077

new macro TLOG() to replace VLOG() for trace logs with a category
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 02 Nov 2020 14:48:15 +0100
parents bf7b9edf6b81
children c7bd2f21ccc3
comparison
equal deleted inserted replaced
4267:a20928107a90 4268:0ae2ca210077
49 LogLevel_ERROR, 49 LogLevel_ERROR,
50 LogLevel_WARNING, 50 LogLevel_WARNING,
51 LogLevel_INFO, 51 LogLevel_INFO,
52 LogLevel_TRACE 52 LogLevel_TRACE
53 }; 53 };
54
55 enum TraceCategory
56 {
57 TraceCategory_GENERIC,
58 TraceCategory_SQLITE,
59 TraceCategory_DICOM
60 };
54 61
55 ORTHANC_PUBLIC const char* EnumerationToString(LogLevel level); 62 ORTHANC_PUBLIC const char* EnumerationToString(LogLevel level);
56 63
57 ORTHANC_PUBLIC LogLevel StringToLogLevel(const char* level); 64 ORTHANC_PUBLIC LogLevel StringToLogLevel(const char* level);
58 65
95 }; 102 };
96 } 103 }
97 } 104 }
98 105
99 106
107
108 /**
109 * NB: The macro "VLOG(unused)" is for backward compatibility with
110 * Orthanc <= 1.8.0.
111 **/
112
100 #if ORTHANC_ENABLE_LOGGING != 1 113 #if ORTHANC_ENABLE_LOGGING != 1
101 # define LOG(level) ::Orthanc::Logging::NullStream() 114 # define LOG(level) ::Orthanc::Logging::NullStream()
102 # define VLOG(level) ::Orthanc::Logging::NullStream() 115 # define VLOG(unused) ::Orthanc::Logging::NullStream()
116 # define TLOG(category) ::Orthanc::Logging::NullStream()
103 #else /* ORTHANC_ENABLE_LOGGING == 1 */ 117 #else /* ORTHANC_ENABLE_LOGGING == 1 */
104 # define LOG(level) ::Orthanc::Logging::InternalLogger \ 118 # define LOG(level) ::Orthanc::Logging::InternalLogger \
105 (::Orthanc::Logging::LogLevel_ ## level, __FILE__, __LINE__) 119 (::Orthanc::Logging::LogLevel_ ## level, \
106 # define VLOG(level) ::Orthanc::Logging::InternalLogger \ 120 ::Orthanc::Logging::TraceCategory_GENERIC, __FILE__, __LINE__)
107 (::Orthanc::Logging::LogLevel_TRACE, __FILE__, __LINE__) 121 # define VLOG(unused) ::Orthanc::Logging::InternalLogger \
122 (::Orthanc::Logging::LogLevel_TRACE, \
123 ::Orthanc::Logging::TraceCategory_GENERIC, __FILE__, __LINE__)
124 # define TLOG(category) ::Orthanc::Logging::InternalLogger \
125 (::Orthanc::Logging::LogLevel_TRACE, \
126 ::Orthanc::Logging::TraceCategory_ ## category, __FILE__, __LINE__)
108 #endif 127 #endif
109 128
110 129
111 130
112 #if (ORTHANC_ENABLE_LOGGING == 1 && \ 131 #if (ORTHANC_ENABLE_LOGGING == 1 && \
123 { 142 {
124 class ORTHANC_PUBLIC InternalLogger : public boost::noncopyable 143 class ORTHANC_PUBLIC InternalLogger : public boost::noncopyable
125 { 144 {
126 private: 145 private:
127 LogLevel level_; 146 LogLevel level_;
147 TraceCategory category_;
128 std::stringstream messageStream_; 148 std::stringstream messageStream_;
129 149
130 public: 150 public:
131 InternalLogger(LogLevel level, 151 InternalLogger(LogLevel level,
152 TraceCategory category,
132 const char* file /* ignored */, 153 const char* file /* ignored */,
133 int line /* ignored */) : 154 int line /* ignored */) :
134 level_(level) 155 level_(level),
156 category_(category)
135 { 157 {
136 } 158 }
137 159
138 ~InternalLogger(); 160 ~InternalLogger();
139 161
167 class ORTHANC_PUBLIC InternalLogger : public boost::noncopyable 189 class ORTHANC_PUBLIC InternalLogger : public boost::noncopyable
168 { 190 {
169 private: 191 private:
170 boost::mutex::scoped_lock lock_; 192 boost::mutex::scoped_lock lock_;
171 LogLevel level_; 193 LogLevel level_;
194 TraceCategory category_;
172 std::unique_ptr<std::stringstream> pluginStream_; 195 std::unique_ptr<std::stringstream> pluginStream_;
173 std::ostream* stream_; 196 std::ostream* stream_;
174 197
175 public: 198 public:
176 InternalLogger(LogLevel level, 199 InternalLogger(LogLevel level,
200 TraceCategory category,
177 const char* file, 201 const char* file,
178 int line); 202 int line);
179 203
180 ~InternalLogger(); 204 ~InternalLogger();
181 205