Mercurial > hg > orthanc-stone
annotate Resources/Orthanc/Core/Logging.h @ 54:01aa453d4d5b wasm
IWidget::HasRenderMouseOver
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 27 Apr 2017 17:49:29 +0200 |
parents | 7207a407bcd8 |
children |
rev | line source |
---|---|
1 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
40
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
5 * Copyright (C) 2017 Osimis, Belgium |
1 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
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/>. | |
31 **/ | |
32 | |
33 | |
34 #pragma once | |
35 | |
36 #include <iostream> | |
37 | |
14 | 38 #if !defined(ORTHANC_ENABLE_LOGGING) |
39 # error The macro ORTHANC_ENABLE_LOGGING must be defined | |
40 #endif | |
41 | |
40
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
42 #if !defined(ORTHANC_ENABLE_LOGGING_PLUGIN) |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
43 # if ORTHANC_ENABLE_LOGGING == 1 |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
44 # error The macro ORTHANC_ENABLE_LOGGING_PLUGIN must be defined |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
45 # else |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
46 # define ORTHANC_ENABLE_LOGGING_PLUGIN 0 |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
47 # endif |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
48 #endif |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
49 |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
50 #if ORTHANC_ENABLE_LOGGING_PLUGIN == 1 |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
51 # include <orthanc/OrthancCPlugin.h> |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
52 #endif |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
53 |
1 | 54 namespace Orthanc |
55 { | |
56 namespace Logging | |
57 { | |
40
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
58 #if ORTHANC_ENABLE_LOGGING_PLUGIN == 1 |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
59 void Initialize(OrthancPluginContext* context); |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
60 #else |
1 | 61 void Initialize(); |
40
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
62 #endif |
1 | 63 |
64 void Finalize(); | |
65 | |
66 void Reset(); | |
67 | |
68 void Flush(); | |
69 | |
70 void EnableInfoLevel(bool enabled); | |
71 | |
72 void EnableTraceLevel(bool enabled); | |
73 | |
74 void SetTargetFile(const std::string& path); | |
75 | |
76 void SetTargetFolder(const std::string& path); | |
77 | |
78 struct NullStream : public std::ostream | |
79 { | |
80 NullStream() : | |
81 std::ios(0), | |
82 std::ostream(0) | |
83 { | |
84 } | |
85 | |
86 std::ostream& operator<< (const std::string& message) | |
87 { | |
88 return *this; | |
89 } | |
90 | |
91 // This overload fixes build problems with Visual Studio 2015 | |
92 std::ostream& operator<< (const char* message) | |
93 { | |
94 return *this; | |
95 } | |
96 }; | |
97 } | |
98 } | |
99 | |
100 | |
101 #if ORTHANC_ENABLE_LOGGING != 1 | |
102 | |
103 # define LOG(level) ::Orthanc::Logging::NullStream() | |
104 # define VLOG(level) ::Orthanc::Logging::NullStream() | |
105 | |
40
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
106 |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
107 #elif ORTHANC_ENABLE_LOGGING_PLUGIN == 1 |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
108 |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
109 # include <boost/noncopyable.hpp> |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
110 # define LOG(level) ::Orthanc::Logging::InternalLogger(#level, __FILE__, __LINE__) |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
111 # define VLOG(level) ::Orthanc::Logging::InternalLogger("TRACE", __FILE__, __LINE__) |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
112 |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
113 namespace Orthanc |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
114 { |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
115 namespace Logging |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
116 { |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
117 class InternalLogger : public boost::noncopyable |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
118 { |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
119 private: |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
120 std::string level_; |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
121 std::string message_; |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
122 |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
123 public: |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
124 InternalLogger(const char* level, |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
125 const char* file, |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
126 int line); |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
127 |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
128 ~InternalLogger(); |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
129 |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
130 InternalLogger& operator<< (const std::string& message); |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
131 |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
132 InternalLogger& operator<< (const char* message); |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
133 |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
134 InternalLogger& operator<< (int message); |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
135 }; |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
136 } |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
137 } |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
138 |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
139 |
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
16
diff
changeset
|
140 #else /* ORTHANC_ENABLE_LOGGING_PLUGIN == 0 && ORTHANC_ENABLE_LOGGING == 1 */ |
1 | 141 |
142 # include <boost/thread/mutex.hpp> | |
143 # define LOG(level) ::Orthanc::Logging::InternalLogger(#level, __FILE__, __LINE__) | |
144 # define VLOG(level) ::Orthanc::Logging::InternalLogger("TRACE", __FILE__, __LINE__) | |
145 | |
146 namespace Orthanc | |
147 { | |
148 namespace Logging | |
149 { | |
150 class InternalLogger | |
151 { | |
152 private: | |
153 boost::mutex::scoped_lock lock_; | |
154 NullStream null_; | |
155 std::ostream* stream_; | |
156 | |
157 public: | |
158 InternalLogger(const char* level, | |
159 const char* file, | |
160 int line); | |
161 | |
162 ~InternalLogger(); | |
163 | |
164 std::ostream& operator<< (const std::string& message) | |
165 { | |
166 return (*stream_) << message; | |
167 } | |
12 | 168 |
169 // This overload fixes build problems with Visual Studio 2015 | |
170 std::ostream& operator<< (const char* message) | |
171 { | |
172 return (*stream_) << message; | |
173 } | |
1 | 174 }; |
175 } | |
176 } | |
177 | |
178 #endif // ORTHANC_ENABLE_LOGGING |