annotate Core/Logging.h @ 4004:9b5ace33a00d

cleaning SetErrorWarnInfoLoggingStreams()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 06 Jun 2020 11:14:10 +0200
parents 3c19371090c3
children 7f9909062d9c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1485
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1551
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1485
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
3992
f9863630ec7f working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
32
f9863630ec7f working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
33
1485
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #pragma once
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
3992
f9863630ec7f working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
36 // 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
37 #include "OrthancFramework.h"
f9863630ec7f working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
38
1551
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
39 #include <iostream>
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
40
2137
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2134
diff changeset
41 #if !defined(ORTHANC_ENABLE_LOGGING)
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2134
diff changeset
42 # error The macro ORTHANC_ENABLE_LOGGING must be defined
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2134
diff changeset
43 #endif
595cf22b3e7e safety checks of macros
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2134
diff changeset
44
2243
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
45 #if !defined(ORTHANC_ENABLE_LOGGING_PLUGIN)
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
46 # if ORTHANC_ENABLE_LOGGING == 1
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
47 # error The macro ORTHANC_ENABLE_LOGGING_PLUGIN must be defined
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
48 # else
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
49 # define ORTHANC_ENABLE_LOGGING_PLUGIN 0
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
50 # endif
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
51 #endif
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
52
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
53 #if !defined(ORTHANC_ENABLE_LOGGING_STDIO)
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
54 # if ORTHANC_ENABLE_LOGGING == 1
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
55 # 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
56 # else
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
57 # define ORTHANC_ENABLE_LOGGING_STDIO 0
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
58 # endif
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
59 #endif
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
60
2504
78862372ea88 fix msvc build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2484
diff changeset
61 #include <boost/lexical_cast.hpp>
78862372ea88 fix msvc build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2484
diff changeset
62
1485
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 namespace Orthanc
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 {
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 namespace Logging
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
3998
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
67 enum LogLevel
3996
c2b9a7a1c74a ORTHANC_FRAMEWORK_BUILDING_PLUGIN
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3995
diff changeset
68 {
3998
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
69 LogLevel_ERROR,
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
70 LogLevel_WARNING,
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
71 LogLevel_INFO,
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
72 LogLevel_TRACE
3996
c2b9a7a1c74a ORTHANC_FRAMEWORK_BUILDING_PLUGIN
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3995
diff changeset
73 };
c2b9a7a1c74a ORTHANC_FRAMEWORK_BUILDING_PLUGIN
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3995
diff changeset
74
3998
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
75 ORTHANC_PUBLIC const char* EnumerationToString(LogLevel level);
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
76
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
77 ORTHANC_PUBLIC LogLevel StringToLogLevel(const char* level);
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
78
2243
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
79 #if ORTHANC_ENABLE_LOGGING_PLUGIN == 1
3995
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3993
diff changeset
80 // "pluginContext" must be of type "OrthancPluginContext"
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3993
diff changeset
81 ORTHANC_PUBLIC void Initialize(void* pluginContext);
2243
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
82 #else
3993
7e8bfda62b43 fix msvc builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
83 ORTHANC_PUBLIC void Initialize();
2243
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
84 #endif
1485
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
3993
7e8bfda62b43 fix msvc builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
86 ORTHANC_PUBLIC void Finalize();
1485
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
3993
7e8bfda62b43 fix msvc builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
88 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
89
3993
7e8bfda62b43 fix msvc builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
90 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
91
3993
7e8bfda62b43 fix msvc builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
92 ORTHANC_PUBLIC void EnableInfoLevel(bool enabled);
1485
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
3993
7e8bfda62b43 fix msvc builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
94 ORTHANC_PUBLIC void EnableTraceLevel(bool enabled);
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
95
3993
7e8bfda62b43 fix msvc builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
96 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
97
3993
7e8bfda62b43 fix msvc builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
98 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
99
3993
7e8bfda62b43 fix msvc builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
100 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
101
3993
7e8bfda62b43 fix msvc builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
102 ORTHANC_PUBLIC void SetTargetFolder(const std::string& path);
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
103
3359
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
104 #if ORTHANC_ENABLE_LOGGING_STDIO == 1
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
105 typedef void (*LoggingFunction)(const char*);
3995
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3993
diff changeset
106 ORTHANC_PUBLIC void SetErrorWarnInfoTraceLoggingFunctions(LoggingFunction errorLogFunc,
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3993
diff changeset
107 LoggingFunction warningLogfunc,
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3993
diff changeset
108 LoggingFunction infoLogFunc,
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3993
diff changeset
109 LoggingFunction traceLogFunc);
3359
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
110 #endif
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
111
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1491
diff changeset
112 struct NullStream : public std::ostream
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1491
diff changeset
113 {
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1491
diff changeset
114 NullStream() :
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1491
diff changeset
115 std::ios(0),
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1491
diff changeset
116 std::ostream(0)
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1491
diff changeset
117 {
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1491
diff changeset
118 }
1551
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
119
2504
78862372ea88 fix msvc build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2484
diff changeset
120 template <typename T>
78862372ea88 fix msvc build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2484
diff changeset
121 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
122 {
1d7a640c1dda fix build issues with Visual Studio 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
123 return *this;
1d7a640c1dda fix build issues with Visual Studio 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
124 }
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1491
diff changeset
125 };
1551
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
126 }
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
127 }
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
128
3998
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
129
1551
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
130 #if ORTHANC_ENABLE_LOGGING != 1
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
131 # define LOG(level) ::Orthanc::Logging::NullStream()
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
132 # define VLOG(level) ::Orthanc::Logging::NullStream()
3998
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
133 #else
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
134 # define LOG(level) ::Orthanc::Logging::InternalLogger \
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
135 (::Orthanc::Logging::LogLevel_ ## level, __FILE__, __LINE__)
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
136 # define VLOG(level) ::Orthanc::Logging::InternalLogger \
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
137 (::Orthanc::Logging::LogLevel_TRACE, __FILE__, __LINE__)
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
138 #endif
2243
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
139
3998
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
140
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
141 #if (ORTHANC_ENABLE_LOGGING == 1 && \
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
142 (ORTHANC_ENABLE_LOGGING_PLUGIN == 1 || \
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
143 ORTHANC_ENABLE_LOGGING_STDIO == 1))
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
144
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
145 #include <boost/noncopyable.hpp>
2243
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
146
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
147 namespace Orthanc
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
148 {
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
149 namespace Logging
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
150 {
3992
f9863630ec7f working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
151 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
152 {
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
153 private:
4001
5d5662ff4d5c unifying loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3998
diff changeset
154 LogLevel level_;
5d5662ff4d5c unifying loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3998
diff changeset
155 std::stringstream messageStream_;
2243
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
156
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
157 public:
3998
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
158 InternalLogger(LogLevel level,
2243
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
159 const char* file,
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
160 int line);
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
161
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
162 ~InternalLogger();
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
163
2484
911e62dbb4ac logging to stdio
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2483
diff changeset
164 template <typename T>
4001
5d5662ff4d5c unifying loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3998
diff changeset
165 std::ostream& operator<< (const T& message)
2484
911e62dbb4ac logging to stdio
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2483
diff changeset
166 {
3489
e7723a39adf8 Fixed alignment issue in Toolbox::DetectEndianness() + made the internal logger
Benjamin Golinvaux <bgo@osimis.io>
parents: 3359
diff changeset
167 messageStream_ << message;
4001
5d5662ff4d5c unifying loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3998
diff changeset
168 return messageStream_;
2484
911e62dbb4ac logging to stdio
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2483
diff changeset
169 }
2243
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
170 };
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
171 }
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
172 }
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
173
3998
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
174 #endif
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
175
2243
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2137
diff changeset
176
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
177
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
178
3998
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
179 #if (ORTHANC_ENABLE_LOGGING == 1 && \
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
180 ORTHANC_ENABLE_LOGGING_PLUGIN == 0 && \
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
181 ORTHANC_ENABLE_LOGGING_STDIO == 0)
1551
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
182
3998
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
183 #include <boost/thread/mutex.hpp>
3995
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3993
diff changeset
184
1551
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
185 namespace Orthanc
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
186 {
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
187 namespace Logging
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
188 {
3992
f9863630ec7f working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
189 class ORTHANC_PUBLIC InternalLogger
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
190 {
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
191 private:
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1491
diff changeset
192 boost::mutex::scoped_lock lock_;
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1491
diff changeset
193 NullStream null_;
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1491
diff changeset
194 std::ostream* stream_;
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
195
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
196 public:
3998
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
197 InternalLogger(LogLevel level,
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
198 const char* file,
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
199 int line);
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
200
1507
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
201 ~InternalLogger();
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1491
diff changeset
202
2504
78862372ea88 fix msvc build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2484
diff changeset
203 template <typename T>
3993
7e8bfda62b43 fix msvc builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
204 std::ostream& operator<< (const T& message)
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
205 {
2504
78862372ea88 fix msvc build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2484
diff changeset
206 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
207 }
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
208 };
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
209
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
210
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
211 /**
4004
9b5ace33a00d cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4003
diff changeset
212 * Set custom logging streams for the error, warning and info
9b5ace33a00d cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4003
diff changeset
213 * 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
214 * has been set beforehand. All three references must be valid.
9b5ace33a00d cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4003
diff changeset
215 *
9b5ace33a00d cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4003
diff changeset
216 * Please ensure the supplied streams remain alive and valid as
9b5ace33a00d cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4003
diff changeset
217 * long as logging calls are performed. In order to prevent
9b5ace33a00d cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4003
diff changeset
218 * dangling pointer usage, it is mandatory to call
9b5ace33a00d cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4003
diff changeset
219 * Orthanc::Logging::Reset() before the stream objects are
9b5ace33a00d cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4003
diff changeset
220 * destroyed and the references become invalid.
9b5ace33a00d cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4003
diff changeset
221 *
9b5ace33a00d cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4003
diff changeset
222 * This function must only be used by unit tests.
9b5ace33a00d cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4003
diff changeset
223 **/
9b5ace33a00d cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4003
diff changeset
224 ORTHANC_PUBLIC void SetErrorWarnInfoLoggingStreams(std::ostream& errorStream,
9b5ace33a00d cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4003
diff changeset
225 std::ostream& warningStream,
9b5ace33a00d cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4003
diff changeset
226 std::ostream& infoStream);
3359
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
227
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
228 #ifdef __EMSCRIPTEN__
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
229 /**
3993
7e8bfda62b43 fix msvc builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
230 This function will change the logging streams so that the logging functions
7e8bfda62b43 fix msvc builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
231 provided by emscripten html5.h API functions are used : it will change the
7e8bfda62b43 fix msvc builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
232 error_, warning_ and info_ stream objects so that their operator<< writes
7e8bfda62b43 fix msvc builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
233 into the browser console using emscripten_console_error(),
7e8bfda62b43 fix msvc builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
234 emscripten_console_warn() and emscripten_console_log(). This will allow for
7e8bfda62b43 fix msvc builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
235 logging levels to be correctly handled by the browser when the code executes
7e8bfda62b43 fix msvc builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
236 in Web Assembly
3359
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
237 */
3993
7e8bfda62b43 fix msvc builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
238 ORTHANC_PUBLIC void EnableEmscriptenLogging();
3359
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
239 #endif
1485
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 }
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 }
1488
c8763b603b0e flag for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1487
diff changeset
242
3998
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
243 #endif