Mercurial > hg > orthanc
annotate OrthancFramework/Sources/Logging.h @ 4224:38d446c9ee1d
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 30 Sep 2020 17:59:09 +0200 |
parents | bf7b9edf6b81 |
children | 0ae2ca210077 |
rev | line source |
---|---|
1485 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1485 | 4 * Department, University Hospital of Liege, Belgium |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
1485 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
10 * the License, or (at your option) any later version. |
1485 | 11 * |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
15 * Lesser General Public License for more details. |
1485 | 16 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
18 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
1485 | 20 **/ |
3992
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
21 |
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
22 |
1485 | 23 #pragma once |
24 | |
3992
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
25 // To have ORTHANC_ENABLE_LOGGING defined if using the shared library |
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
26 #include "OrthancFramework.h" |
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
27 |
1551
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
28 #include <iostream> |
1489 | 29 |
2137
595cf22b3e7e
safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2134
diff
changeset
|
30 #if !defined(ORTHANC_ENABLE_LOGGING) |
595cf22b3e7e
safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2134
diff
changeset
|
31 # error The macro ORTHANC_ENABLE_LOGGING must be defined |
595cf22b3e7e
safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2134
diff
changeset
|
32 #endif |
595cf22b3e7e
safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2134
diff
changeset
|
33 |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
34 #if !defined(ORTHANC_ENABLE_LOGGING_STDIO) |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
35 # if ORTHANC_ENABLE_LOGGING == 1 |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
36 # error The macro ORTHANC_ENABLE_LOGGING_STDIO must be defined |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
37 # else |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
38 # define ORTHANC_ENABLE_LOGGING_STDIO 0 |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
39 # endif |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
40 #endif |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
41 |
2504 | 42 |
1485 | 43 namespace Orthanc |
44 { | |
45 namespace Logging | |
46 { | |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
47 enum LogLevel |
3996
c2b9a7a1c74a
ORTHANC_FRAMEWORK_BUILDING_PLUGIN
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3995
diff
changeset
|
48 { |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
49 LogLevel_ERROR, |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
50 LogLevel_WARNING, |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
51 LogLevel_INFO, |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
52 LogLevel_TRACE |
3996
c2b9a7a1c74a
ORTHANC_FRAMEWORK_BUILDING_PLUGIN
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3995
diff
changeset
|
53 }; |
c2b9a7a1c74a
ORTHANC_FRAMEWORK_BUILDING_PLUGIN
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3995
diff
changeset
|
54 |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
55 ORTHANC_PUBLIC const char* EnumerationToString(LogLevel level); |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
56 |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
57 ORTHANC_PUBLIC LogLevel StringToLogLevel(const char* level); |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
58 |
3995
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3993
diff
changeset
|
59 // "pluginContext" must be of type "OrthancPluginContext" |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
60 ORTHANC_PUBLIC void InitializePluginContext(void* pluginContext); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
61 |
3993 | 62 ORTHANC_PUBLIC void Initialize(); |
1485 | 63 |
3993 | 64 ORTHANC_PUBLIC void Finalize(); |
1485 | 65 |
3993 | 66 ORTHANC_PUBLIC void Reset(); |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
67 |
3993 | 68 ORTHANC_PUBLIC void Flush(); |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
69 |
3993 | 70 ORTHANC_PUBLIC void EnableInfoLevel(bool enabled); |
1485 | 71 |
3993 | 72 ORTHANC_PUBLIC void EnableTraceLevel(bool enabled); |
1489 | 73 |
3993 | 74 ORTHANC_PUBLIC bool IsTraceLevelEnabled(); |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
75 |
3993 | 76 ORTHANC_PUBLIC bool IsInfoLevelEnabled(); |
3353
54cdad5a7228
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
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
77 |
3993 | 78 ORTHANC_PUBLIC void SetTargetFile(const std::string& path); |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
79 |
3993 | 80 ORTHANC_PUBLIC void SetTargetFolder(const std::string& path); |
1489 | 81 |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1491
diff
changeset
|
82 struct NullStream : public std::ostream |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1491
diff
changeset
|
83 { |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1491
diff
changeset
|
84 NullStream() : |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1491
diff
changeset
|
85 std::ios(0), |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1491
diff
changeset
|
86 std::ostream(0) |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1491
diff
changeset
|
87 { |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1491
diff
changeset
|
88 } |
1551
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
89 |
2504 | 90 template <typename T> |
91 std::ostream& operator<< (const T& message) | |
2073
1d7a640c1dda
fix build issues with Visual Studio 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
92 { |
1d7a640c1dda
fix build issues with Visual Studio 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
93 return *this; |
1d7a640c1dda
fix build issues with Visual Studio 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
94 } |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1491
diff
changeset
|
95 }; |
1551
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
96 } |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
97 } |
1489 | 98 |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
99 |
1551
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
100 #if ORTHANC_ENABLE_LOGGING != 1 |
4017
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
101 # define LOG(level) ::Orthanc::Logging::NullStream() |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
102 # define VLOG(level) ::Orthanc::Logging::NullStream() |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
103 #else /* ORTHANC_ENABLE_LOGGING == 1 */ |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
104 # define LOG(level) ::Orthanc::Logging::InternalLogger \ |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
105 (::Orthanc::Logging::LogLevel_ ## level, __FILE__, __LINE__) |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
106 # define VLOG(level) ::Orthanc::Logging::InternalLogger \ |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
107 (::Orthanc::Logging::LogLevel_TRACE, __FILE__, __LINE__) |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
108 #endif |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
109 |
4017
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
110 |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
111 |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
112 #if (ORTHANC_ENABLE_LOGGING == 1 && \ |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
113 ORTHANC_ENABLE_LOGGING_STDIO == 1) |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
114 // This is notably for WebAssembly |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
115 |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
116 #include <boost/lexical_cast.hpp> |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
117 #include <boost/noncopyable.hpp> |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
118 #include <sstream> |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
119 |
4017
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
120 namespace Orthanc |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
121 { |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
122 namespace Logging |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
123 { |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
124 class ORTHANC_PUBLIC InternalLogger : public boost::noncopyable |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
125 { |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
126 private: |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
127 LogLevel level_; |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
128 std::stringstream messageStream_; |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
129 |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
130 public: |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
131 InternalLogger(LogLevel level, |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
132 const char* file /* ignored */, |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
133 int line /* ignored */) : |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
134 level_(level) |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
135 { |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
136 } |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
137 |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
138 ~InternalLogger(); |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
139 |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
140 template <typename T> |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
141 std::ostream& operator<< (const T& message) |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
142 { |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
143 return messageStream_ << boost::lexical_cast<std::string>(message); |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
144 } |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
145 }; |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
146 } |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
147 } |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
148 |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
149 #endif |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
150 |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
151 |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
152 |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
153 #if (ORTHANC_ENABLE_LOGGING == 1 && \ |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
154 ORTHANC_ENABLE_LOGGING_STDIO == 0) |
2243
2dbfdafc2512
Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2137
diff
changeset
|
155 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
156 #include "Compatibility.h" // For std::unique_ptr<> |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
157 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
158 #include <boost/lexical_cast.hpp> |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
159 #include <boost/noncopyable.hpp> |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
160 #include <boost/thread/mutex.hpp> |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
161 #include <sstream> |
2243
2dbfdafc2512
Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2137
diff
changeset
|
162 |
2dbfdafc2512
Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2137
diff
changeset
|
163 namespace Orthanc |
2dbfdafc2512
Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2137
diff
changeset
|
164 { |
2dbfdafc2512
Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2137
diff
changeset
|
165 namespace Logging |
2dbfdafc2512
Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2137
diff
changeset
|
166 { |
3992
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
167 class ORTHANC_PUBLIC InternalLogger : public boost::noncopyable |
2243
2dbfdafc2512
Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2137
diff
changeset
|
168 { |
2dbfdafc2512
Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2137
diff
changeset
|
169 private: |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
170 boost::mutex::scoped_lock lock_; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
171 LogLevel level_; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
172 std::unique_ptr<std::stringstream> pluginStream_; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
173 std::ostream* stream_; |
1489 | 174 |
175 public: | |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
176 InternalLogger(LogLevel level, |
1489 | 177 const char* file, |
178 int line); | |
179 | |
1507 | 180 ~InternalLogger(); |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1491
diff
changeset
|
181 |
2504 | 182 template <typename T> |
3993 | 183 std::ostream& operator<< (const T& message) |
1489 | 184 { |
2504 | 185 return (*stream_) << boost::lexical_cast<std::string>(message); |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2073
diff
changeset
|
186 } |
1489 | 187 }; |
3353
54cdad5a7228
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
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
188 |
54cdad5a7228
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
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
189 |
54cdad5a7228
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
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
190 /** |
4004
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
191 * Set custom logging streams for the error, warning and info |
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
192 * logs. This function may not be called if a log file or folder |
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
193 * has been set beforehand. All three references must be valid. |
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
194 * |
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
195 * Please ensure the supplied streams remain alive and valid as |
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
196 * long as logging calls are performed. In order to prevent |
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
197 * dangling pointer usage, it is mandatory to call |
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
198 * Orthanc::Logging::Reset() before the stream objects are |
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
199 * destroyed and the references become invalid. |
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
200 * |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
201 * This function must only be used by unit tests. It is ignored if |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
202 * InitializePluginContext() was called. |
4004
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
203 **/ |
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
204 ORTHANC_PUBLIC void SetErrorWarnInfoLoggingStreams(std::ostream& errorStream, |
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
205 std::ostream& warningStream, |
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
206 std::ostream& infoStream); |
1485 | 207 } |
208 } | |
1488 | 209 |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
210 #endif |