Mercurial > hg > orthanc
annotate Core/Logging.cpp @ 4010:f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 08 Jun 2020 15:54:30 +0200 |
parents | 55710d73780f |
children | 27628b0f6ada |
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:
3629
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 | |
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 #include "PrecompiledHeaders.h" | |
35 #include "Logging.h" | |
36 | |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
37 #include "OrthancException.h" |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
38 |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
39 |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
40 namespace Orthanc |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
41 { |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
42 namespace Logging |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
43 { |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
44 const char* EnumerationToString(LogLevel level) |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
45 { |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
46 switch (level) |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
47 { |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
48 case LogLevel_ERROR: |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
49 return "ERROR"; |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
50 |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
51 case LogLevel_WARNING: |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
52 return "WARNING"; |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
53 |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
54 case LogLevel_INFO: |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
55 return "INFO"; |
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 case LogLevel_TRACE: |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
58 return "TRACE"; |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
59 |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
60 default: |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
61 throw OrthancException(ErrorCode_ParameterOutOfRange); |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
62 } |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
63 } |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
64 |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
65 |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
66 LogLevel StringToLogLevel(const char *level) |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
67 { |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
68 if (strcmp(level, "ERROR") == 0) |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
69 { |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
70 return LogLevel_ERROR; |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
71 } |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
72 else if (strcmp(level, "WARNING") == 0) |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
73 { |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
74 return LogLevel_WARNING; |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
75 } |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
76 else if (strcmp(level, "INFO") == 0) |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
77 { |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
78 return LogLevel_INFO; |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
79 } |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
80 else if (strcmp(level, "TRACE") == 0) |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
81 { |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
82 return LogLevel_TRACE; |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
83 } |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
84 else |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
85 { |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
86 throw OrthancException(ErrorCode_InternalError); |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
87 } |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
88 } |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
89 } |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
90 } |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
91 |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
92 |
1551
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
93 #if ORTHANC_ENABLE_LOGGING != 1 |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
94 |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
95 namespace Orthanc |
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 namespace Logging |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
98 { |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
99 void Initialize() |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
100 { |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
101 } |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
102 |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
103 void Finalize() |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
104 { |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
105 } |
1485 | 106 |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
107 void Reset() |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
108 { |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
109 } |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
110 |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
111 void Flush() |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
112 { |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
113 } |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
114 |
1551
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
115 void EnableInfoLevel(bool enabled) |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
116 { |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
117 } |
1489 | 118 |
1551
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
119 void EnableTraceLevel(bool enabled) |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
120 { |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
121 } |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
122 |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
123 bool IsTraceLevelEnabled() |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
124 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
125 return false; |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
126 } |
1551
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
127 |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
128 bool IsInfoLevelEnabled() |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
129 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
130 return false; |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
131 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
132 |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
133 void SetTargetFile(const std::string& path) |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
134 { |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
135 } |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
136 |
1551
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
137 void SetTargetFolder(const std::string& path) |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
138 { |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
139 } |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
140 } |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
141 } |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
142 |
2243
2dbfdafc2512
Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2143
diff
changeset
|
143 |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
144 #elif ORTHANC_ENABLE_LOGGING_STDIO == 1 |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
145 |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
146 /********************************************************* |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
147 * Logger compatible with <stdio.h> OR logger that sends its |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
148 * output to the emscripten html5 api (depending on the |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
149 * definition of __EMSCRIPTEN__) |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
150 *********************************************************/ |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
151 |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
152 #include <stdio.h> |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
153 #include <boost/lexical_cast.hpp> |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
154 |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
155 #ifdef __EMSCRIPTEN__ |
3506
d2b9981017c4
better handling of HTTP security
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
156 # include <emscripten/html5.h> |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
157 #endif |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
158 |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
159 namespace Orthanc |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
160 { |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
161 namespace Logging |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
162 { |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
163 static bool globalVerbose_ = false; |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
164 static bool globalTrace_ = false; |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
165 |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
166 #ifdef __EMSCRIPTEN__ |
4010
f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4006
diff
changeset
|
167 static void ErrorLogFunc(const char* msg) |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
168 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
169 emscripten_console_error(msg); |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
170 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
171 |
4010
f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4006
diff
changeset
|
172 static void WarningLogFunc(const char* msg) |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
173 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
174 emscripten_console_warn(msg); |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
175 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
176 |
4010
f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4006
diff
changeset
|
177 static void InfoLogFunc(const char* msg) |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
178 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
179 emscripten_console_log(msg); |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
180 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
181 |
4010
f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4006
diff
changeset
|
182 static void TraceLogFunc(const char* msg) |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
183 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
184 emscripten_console_log(msg); |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
185 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
186 #else |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
187 // __EMSCRIPTEN__ not #defined |
4010
f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4006
diff
changeset
|
188 static void ErrorLogFunc(const char* msg) |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
189 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
190 fprintf(stderr, "E: %s\n", msg); |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
191 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
192 |
4010
f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4006
diff
changeset
|
193 static void WarningLogFunc(const char*) |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
194 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
195 fprintf(stdout, "W: %s\n", msg); |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
196 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
197 |
4010
f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4006
diff
changeset
|
198 static void InfoLogFunc(const char*) |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
199 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
200 fprintf(stdout, "I: %s\n", msg); |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
201 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
202 |
4010
f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4006
diff
changeset
|
203 static void TraceLogFunc(const char*) |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
204 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
205 fprintf(stdout, "T: %s\n", msg); |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
206 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
207 #endif |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
208 // __EMSCRIPTEN__ |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
209 |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
210 InternalLogger::InternalLogger(LogLevel level, |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
211 const char* file /* ignored */, |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
212 int line /* ignored */) : |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
213 level_(level) |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
214 { |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
215 } |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
216 |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
217 InternalLogger::~InternalLogger() |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
218 { |
3489
e7723a39adf8
Fixed alignment issue in Toolbox::DetectEndianness() + made the internal logger
Benjamin Golinvaux <bgo@osimis.io>
parents:
3477
diff
changeset
|
219 std::string message = messageStream_.str(); |
e7723a39adf8
Fixed alignment issue in Toolbox::DetectEndianness() + made the internal logger
Benjamin Golinvaux <bgo@osimis.io>
parents:
3477
diff
changeset
|
220 |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
221 switch (level_) |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
222 { |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
223 case LogLevel_ERROR: |
3489
e7723a39adf8
Fixed alignment issue in Toolbox::DetectEndianness() + made the internal logger
Benjamin Golinvaux <bgo@osimis.io>
parents:
3477
diff
changeset
|
224 globalErrorLogFunc(message.c_str()); |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
225 break; |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
226 |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
227 case LogLevel_WARNING: |
3489
e7723a39adf8
Fixed alignment issue in Toolbox::DetectEndianness() + made the internal logger
Benjamin Golinvaux <bgo@osimis.io>
parents:
3477
diff
changeset
|
228 globalWarningLogFunc(message.c_str()); |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
229 break; |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
230 |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
231 case LogLevel_INFO: |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
232 if (globalVerbose_) |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
233 { |
3489
e7723a39adf8
Fixed alignment issue in Toolbox::DetectEndianness() + made the internal logger
Benjamin Golinvaux <bgo@osimis.io>
parents:
3477
diff
changeset
|
234 globalInfoLogFunc(message.c_str()); |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
235 // TODO: stone_console_info(message_.c_str()); |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
236 } |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
237 break; |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
238 |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
239 case LogLevel_TRACE: |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
240 if (globalTrace_) |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
241 { |
3489
e7723a39adf8
Fixed alignment issue in Toolbox::DetectEndianness() + made the internal logger
Benjamin Golinvaux <bgo@osimis.io>
parents:
3477
diff
changeset
|
242 globalTraceLogFunc(message.c_str()); |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
243 } |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
244 break; |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
245 |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
246 default: |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
247 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
248 std::stringstream ss; |
3489
e7723a39adf8
Fixed alignment issue in Toolbox::DetectEndianness() + made the internal logger
Benjamin Golinvaux <bgo@osimis.io>
parents:
3477
diff
changeset
|
249 ss << "Unknown log level (" << level_ << ") for message: " << message; |
3505
b2d4dd16dae8
removed C++11 primitive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
250 std::string s = ss.str(); |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
251 globalErrorLogFunc(s.c_str()); |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
252 } |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
253 } |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
254 } |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
255 |
3358
849c651c1381
fix missing symbol
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
256 void Initialize() |
849c651c1381
fix missing symbol
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
257 { |
849c651c1381
fix missing symbol
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
258 } |
849c651c1381
fix missing symbol
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
259 |
3995
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
260 void Finalize() |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
261 { |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
262 } |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
263 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
264 void Reset() |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
265 { |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
266 } |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
267 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
268 void Flush() |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
269 { |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
270 } |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
271 |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
272 void EnableInfoLevel(bool enabled) |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
273 { |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
274 globalVerbose_ = enabled; |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
275 } |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
276 |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
277 bool IsInfoLevelEnabled() |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
278 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
279 return globalVerbose_; |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
280 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
281 |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
282 void EnableTraceLevel(bool enabled) |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
283 { |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
284 globalTrace_ = enabled; |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
285 } |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
286 |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
287 bool IsTraceLevelEnabled() |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
288 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
289 return globalTrace_; |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
290 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
291 |
3995
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
292 void SetTargetFile(const std::string& path) |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
293 { |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
294 } |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
295 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
296 void SetTargetFolder(const std::string& path) |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
297 { |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
298 } |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
299 } |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
300 } |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
301 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
302 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
303 #elif ORTHANC_ENABLE_LOGGING_PLUGIN == 1 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
304 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
305 /********************************************************* |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
306 * Logger compatible with the Orthanc plugin SDK |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
307 *********************************************************/ |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
308 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
309 #include <cassert> |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
310 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
311 namespace |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
312 { |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
313 /** |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
314 * This is minimal implementation of the context for an Orthanc |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
315 * plugin, limited to the logging facilities, and that is binary |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
316 * compatible with the definitions of "OrthancCPlugin.h" |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
317 **/ |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
318 typedef enum |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
319 { |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
320 _OrthancPluginService_LogInfo = 1, |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
321 _OrthancPluginService_LogWarning = 2, |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
322 _OrthancPluginService_LogError = 3, |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
323 _OrthancPluginService_INTERNAL = 0x7fffffff |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
324 } _OrthancPluginService; |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
325 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
326 typedef struct _OrthancPluginContext_t |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
327 { |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
328 void* pluginsManager; |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
329 const char* orthancVersion; |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
330 void (*Free) (void* buffer); |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
331 int32_t (*InvokeService) (struct _OrthancPluginContext_t* context, |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
332 _OrthancPluginService service, |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
333 const void* params); |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
334 } OrthancPluginContext; |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
335 } |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
336 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
337 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
338 #include <boost/lexical_cast.hpp> |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
339 #include <sstream> |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
340 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
341 namespace Orthanc |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
342 { |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
343 namespace Logging |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
344 { |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
345 static OrthancPluginContext* context_ = NULL; |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
346 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
347 void Initialize(void* context) |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
348 { |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
349 assert(sizeof(_OrthancPluginService) == sizeof(int32_t)); |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
350 context_ = reinterpret_cast<OrthancPluginContext*>(context); |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
351 } |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
352 |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
353 InternalLogger::InternalLogger(LogLevel level, |
3995
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
354 const char* file /* ignored */, |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
355 int line /* ignored */) : |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
356 level_(level) |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
357 { |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
358 } |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
359 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
360 InternalLogger::~InternalLogger() |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
361 { |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
362 std::string message = messageStream_.str(); |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
363 if (context_ != NULL) |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
364 { |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
365 switch (level_) |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
366 { |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
367 case LogLevel_ERROR: |
3995
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
368 context_->InvokeService(context_, _OrthancPluginService_LogError, message.c_str()); |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
369 break; |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
370 |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
371 case LogLevel_WARNING: |
3995
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
372 context_->InvokeService(context_, _OrthancPluginService_LogWarning, message.c_str()); |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
373 break; |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
374 |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
375 case LogLevel_INFO: |
3995
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
376 context_->InvokeService(context_, _OrthancPluginService_LogInfo, message.c_str()); |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
377 break; |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
378 |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
379 case LogLevel_TRACE: |
3995
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
380 // Not used by plugins |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
381 break; |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
382 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
383 default: |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
384 { |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
385 std::string s = ("Unknown log level (" + boost::lexical_cast<std::string>(level_) + |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
386 ") for message: " + message); |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
387 context_->InvokeService(context_, _OrthancPluginService_LogInfo, s.c_str()); |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
388 break; |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
389 } |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
390 } |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
391 } |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
392 } |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
393 } |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
394 } |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
395 |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
396 |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
397 #else /* ORTHANC_ENABLE_LOGGING_PLUGIN == 0 && |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
398 ORTHANC_ENABLE_LOGGING_STDIO == 0 && |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
399 ORTHANC_ENABLE_LOGGING == 1 */ |
1489 | 400 |
401 /********************************************************* | |
2014
e39a2657f1c6
Dropped support of Google Log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
402 * Internal logger of Orthanc, that mimics some |
e39a2657f1c6
Dropped support of Google Log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
403 * behavior from Google Log. |
1489 | 404 *********************************************************/ |
405 | |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
406 #include "Compatibility.h" |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
407 #include "Enumerations.h" |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
408 #include "Toolbox.h" |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
409 |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
410 #if ORTHANC_SANDBOXED == 1 |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
411 # include <stdio.h> |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
412 #else |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
413 # include "SystemToolbox.h" |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
414 #endif |
1489 | 415 |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
416 #include <fstream> |
1489 | 417 #include <boost/filesystem.hpp> |
418 #include <boost/thread.hpp> | |
2367
2aff870c2c58
refactoring of BoostConfiguration.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2253
diff
changeset
|
419 #include <boost/date_time/posix_time/posix_time.hpp> |
1489 | 420 |
421 | |
422 namespace | |
423 { | |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
424 struct LoggingContext |
1489 | 425 { |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
426 bool infoEnabled_; |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
427 bool traceEnabled_; |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
428 std::string targetFile_; |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
429 std::string targetFolder_; |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
430 |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
431 std::ostream* error_; |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
432 std::ostream* warning_; |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
433 std::ostream* info_; |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
434 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
435 std::unique_ptr<std::ofstream> file_; |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
436 |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
437 LoggingContext() : |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
438 infoEnabled_(false), |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
439 traceEnabled_(false), |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
440 error_(&std::cerr), |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
441 warning_(&std::cerr), |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
442 info_(&std::cerr) |
1489 | 443 { |
444 } | |
445 }; | |
446 } | |
447 | |
448 | |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
449 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
450 static std::unique_ptr<LoggingContext> loggingContext_; |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
451 static boost::mutex loggingMutex_; |
1489 | 452 |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
453 |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
454 |
1489 | 455 namespace Orthanc |
456 { | |
457 namespace Logging | |
458 { | |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
459 static void GetLogPath(boost::filesystem::path& log, |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
460 boost::filesystem::path& link, |
1731
b6f656a0bf2c
"--logdir" creates a single log file instead of 3 separate files for errors/warnings/infos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1551
diff
changeset
|
461 const std::string& suffix, |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
462 const std::string& directory) |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
463 { |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
464 /** |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
465 From Google Log documentation: |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
466 |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
467 Unless otherwise specified, logs will be written to the filename |
1731
b6f656a0bf2c
"--logdir" creates a single log file instead of 3 separate files for errors/warnings/infos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1551
diff
changeset
|
468 "<program name>.<hostname>.<user name>.log<suffix>.", |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
469 followed by the date, time, and pid (you can't prevent the date, |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
470 time, and pid from being in the filename). |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
471 |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
472 In this implementation : "hostname" and "username" are not used |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
473 **/ |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
474 |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
475 boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
476 boost::filesystem::path root(directory); |
2140 | 477 boost::filesystem::path exe(SystemToolbox::GetPathToExecutable()); |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
478 |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
479 if (!boost::filesystem::exists(root) || |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
480 !boost::filesystem::is_directory(root)) |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
481 { |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
482 throw OrthancException(ErrorCode_CannotWriteFile); |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
483 } |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
484 |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
485 char date[64]; |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
486 sprintf(date, "%04d%02d%02d-%02d%02d%02d.%d", |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
487 static_cast<int>(now.date().year()), |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
488 now.date().month().as_number(), |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
489 now.date().day().as_number(), |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
490 static_cast<int>(now.time_of_day().hours()), |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
491 static_cast<int>(now.time_of_day().minutes()), |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
492 static_cast<int>(now.time_of_day().seconds()), |
2140 | 493 SystemToolbox::GetProcessId()); |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
494 |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
495 std::string programName = exe.filename().replace_extension("").string(); |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
496 |
1731
b6f656a0bf2c
"--logdir" creates a single log file instead of 3 separate files for errors/warnings/infos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1551
diff
changeset
|
497 log = (root / (programName + ".log" + suffix + "." + std::string(date))); |
b6f656a0bf2c
"--logdir" creates a single log file instead of 3 separate files for errors/warnings/infos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1551
diff
changeset
|
498 link = (root / (programName + ".log" + suffix)); |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
499 } |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
500 |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
501 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
502 static void PrepareLogFolder(std::unique_ptr<std::ofstream>& file, |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
503 const std::string& suffix, |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
504 const std::string& directory) |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
505 { |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
506 boost::filesystem::path log, link; |
1731
b6f656a0bf2c
"--logdir" creates a single log file instead of 3 separate files for errors/warnings/infos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1551
diff
changeset
|
507 GetLogPath(log, link, suffix, directory); |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
508 |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
509 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
510 boost::filesystem::remove(link); |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
511 boost::filesystem::create_symlink(log.filename(), link); |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
512 #endif |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
513 |
1494 | 514 file.reset(new std::ofstream(log.string().c_str())); |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
515 } |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
516 |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
517 |
4006
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
518 static void CheckFile(std::unique_ptr<std::ofstream>& f) |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
519 { |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
520 if (loggingContext_->file_.get() == NULL || |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
521 !loggingContext_->file_->is_open()) |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
522 { |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
523 throw OrthancException(ErrorCode_CannotWriteFile); |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
524 } |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
525 } |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
526 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
527 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
528 static void GetLinePrefix(std::string& prefix, |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
529 LogLevel level, |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
530 const char* file, |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
531 int line) |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
532 { |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
533 boost::filesystem::path path(file); |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
534 boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time(); |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
535 boost::posix_time::time_duration duration = now.time_of_day(); |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
536 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
537 /** |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
538 From Google Log documentation: |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
539 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
540 "Log lines have this form: |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
541 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
542 Lmmdd hh:mm:ss.uuuuuu threadid file:line] msg... |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
543 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
544 where the fields are defined as follows: |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
545 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
546 L A single character, representing the log level (eg 'I' for INFO) |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
547 mm The month (zero padded; ie May is '05') |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
548 dd The day (zero padded) |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
549 hh:mm:ss.uuuuuu Time in hours, minutes and fractional seconds |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
550 threadid The space-padded thread ID as returned by GetTID() (this matches the PID on Linux) |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
551 file The file name |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
552 line The line number |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
553 msg The user-supplied message" |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
554 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
555 In this implementation, "threadid" is not printed. |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
556 **/ |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
557 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
558 char c; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
559 switch (level) |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
560 { |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
561 case LogLevel_ERROR: |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
562 c = 'E'; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
563 break; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
564 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
565 case LogLevel_WARNING: |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
566 c = 'W'; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
567 break; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
568 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
569 case LogLevel_INFO: |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
570 c = 'I'; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
571 break; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
572 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
573 case LogLevel_TRACE: |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
574 c = 'T'; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
575 break; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
576 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
577 default: |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
578 throw OrthancException(ErrorCode_InternalError); |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
579 } |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
580 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
581 char date[64]; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
582 sprintf(date, "%c%02d%02d %02d:%02d:%02d.%06d ", |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
583 c, |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
584 now.date().month().as_number(), |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
585 now.date().day().as_number(), |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
586 static_cast<int>(duration.hours()), |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
587 static_cast<int>(duration.minutes()), |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
588 static_cast<int>(duration.seconds()), |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
589 static_cast<int>(duration.fractional_seconds())); |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
590 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
591 prefix = (std::string(date) + path.filename().string() + ":" + |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
592 boost::lexical_cast<std::string>(line) + "] "); |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
593 } |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
594 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
595 |
1489 | 596 void Initialize() |
597 { | |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
598 boost::mutex::scoped_lock lock(loggingMutex_); |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
599 loggingContext_.reset(new LoggingContext); |
1489 | 600 } |
601 | |
602 void Finalize() | |
603 { | |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
604 boost::mutex::scoped_lock lock(loggingMutex_); |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
605 loggingContext_.reset(NULL); |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
606 } |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
607 |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
608 void Reset() |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
609 { |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
610 // Recover the old logging context |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
611 std::unique_ptr<LoggingContext> old; |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
612 |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
613 { |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
614 boost::mutex::scoped_lock lock(loggingMutex_); |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
615 if (loggingContext_.get() == NULL) |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
616 { |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
617 return; |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
618 } |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
619 else |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
620 { |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
621 #if __cplusplus < 201103L |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
622 old.reset(loggingContext_.release()); |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
623 #else |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
624 old = std::move(loggingContext_); |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
625 #endif |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
626 |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
627 // Create a new logging context, |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
628 loggingContext_.reset(new LoggingContext); |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
629 } |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
630 } |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
631 |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
632 EnableInfoLevel(old->infoEnabled_); |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
633 EnableTraceLevel(old->traceEnabled_); |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
634 |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
635 if (!old->targetFolder_.empty()) |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
636 { |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
637 SetTargetFolder(old->targetFolder_); |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
638 } |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
639 else if (!old->targetFile_.empty()) |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
640 { |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
641 SetTargetFile(old->targetFile_); |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
642 } |
1489 | 643 } |
644 | |
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
|
645 |
1489 | 646 void EnableInfoLevel(bool enabled) |
647 { | |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
648 boost::mutex::scoped_lock lock(loggingMutex_); |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
649 assert(loggingContext_.get() != NULL); |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
650 |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
651 loggingContext_->infoEnabled_ = enabled; |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
652 |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
653 if (!enabled) |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
654 { |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
655 // Also disable the "TRACE" level when info-level debugging is disabled |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
656 loggingContext_->traceEnabled_ = false; |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
657 } |
1489 | 658 } |
659 | |
3629
19966d299685
Fixed typo in function impl name
Benjamin Golinvaux <bgo@osimis.io>
parents:
3506
diff
changeset
|
660 bool IsInfoLevelEnabled() |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
661 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
662 boost::mutex::scoped_lock lock(loggingMutex_); |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
663 assert(loggingContext_.get() != NULL); |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
664 |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
665 return loggingContext_->infoEnabled_; |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
666 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
667 |
1489 | 668 void EnableTraceLevel(bool enabled) |
669 { | |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
670 boost::mutex::scoped_lock lock(loggingMutex_); |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
671 assert(loggingContext_.get() != NULL); |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
672 |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
673 loggingContext_->traceEnabled_ = enabled; |
1489 | 674 |
675 if (enabled) | |
676 { | |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
677 // Also enable the "INFO" level when trace-level debugging is enabled |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
678 loggingContext_->infoEnabled_ = true; |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
679 } |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
680 } |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
681 |
3629
19966d299685
Fixed typo in function impl name
Benjamin Golinvaux <bgo@osimis.io>
parents:
3506
diff
changeset
|
682 bool IsTraceLevelEnabled() |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
683 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
684 boost::mutex::scoped_lock lock(loggingMutex_); |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
685 assert(loggingContext_.get() != NULL); |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
686 |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
687 return loggingContext_->traceEnabled_; |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
688 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
689 |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
690 |
1489 | 691 void SetTargetFolder(const std::string& path) |
692 { | |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
693 boost::mutex::scoped_lock lock(loggingMutex_); |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
694 assert(loggingContext_.get() != NULL); |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
695 |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
696 PrepareLogFolder(loggingContext_->file_, "" /* no suffix */, path); |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
697 CheckFile(loggingContext_->file_); |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
698 |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
699 loggingContext_->targetFile_.clear(); |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
700 loggingContext_->targetFolder_ = path; |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
701 loggingContext_->warning_ = loggingContext_->file_.get(); |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
702 loggingContext_->error_ = loggingContext_->file_.get(); |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
703 loggingContext_->info_ = loggingContext_->file_.get(); |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
704 } |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
705 |
1731
b6f656a0bf2c
"--logdir" creates a single log file instead of 3 separate files for errors/warnings/infos
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1551
diff
changeset
|
706 |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
707 void SetTargetFile(const std::string& path) |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
708 { |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
709 boost::mutex::scoped_lock lock(loggingMutex_); |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
710 assert(loggingContext_.get() != NULL); |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
711 |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
712 loggingContext_->file_.reset(new std::ofstream(path.c_str(), std::fstream::app)); |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
713 CheckFile(loggingContext_->file_); |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
714 |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
715 loggingContext_->targetFile_ = path; |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
716 loggingContext_->targetFolder_.clear(); |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
717 loggingContext_->warning_ = loggingContext_->file_.get(); |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
718 loggingContext_->error_ = loggingContext_->file_.get(); |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
719 loggingContext_->info_ = loggingContext_->file_.get(); |
1489 | 720 } |
721 | |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
722 |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
723 InternalLogger::InternalLogger(LogLevel level, |
1489 | 724 const char* file, |
725 int line) : | |
4010
f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4006
diff
changeset
|
726 lock_(loggingMutex_, boost::defer_lock_t()), |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
727 stream_(&null_) // By default, logging to "/dev/null" is simulated |
1489 | 728 { |
4010
f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4006
diff
changeset
|
729 lock_.lock(); |
f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4006
diff
changeset
|
730 |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
731 if (loggingContext_.get() == NULL) |
1489 | 732 { |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
733 fprintf(stderr, "ERROR: Trying to log a message after the finalization of the logging engine\n"); |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
734 return; |
1489 | 735 } |
736 | |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
737 try |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
738 { |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
739 if ((level == LogLevel_INFO && !loggingContext_->infoEnabled_) || |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
740 (level == LogLevel_TRACE && !loggingContext_->traceEnabled_)) |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
741 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
742 // This logging level is disabled, directly exit and unlock |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
743 // the mutex to speed-up things. The stream is set to "/dev/null" |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
744 lock_.unlock(); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
745 return; |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
746 } |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
747 |
4006
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
748 // Compute the prefix of the line, temporary release the lock as |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
749 // this is a time-consuming operation |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
750 lock_.unlock(); |
4006
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
751 std::string prefix; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
752 GetLinePrefix(prefix, level, file, line); |
1489 | 753 |
4006
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
754 // The prefix is computed, we now re-lock the mutex to access |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
755 // the stream objects. Pay attention that "loggingContext_", |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
756 // "infoEnabled_" or "traceEnabled_" might have changed while |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
757 // the mutex was unlocked. |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
758 lock_.lock(); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
759 |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
760 if (loggingContext_.get() == NULL) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
761 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
762 fprintf(stderr, "ERROR: Trying to log a message after the finalization of the logging engine\n"); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
763 return; |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
764 } |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
765 |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
766 switch (level) |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
767 { |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
768 case LogLevel_ERROR: |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
769 stream_ = loggingContext_->error_; |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
770 break; |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
771 |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
772 case LogLevel_WARNING: |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
773 stream_ = loggingContext_->warning_; |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
774 break; |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
775 |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
776 case LogLevel_INFO: |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
777 if (loggingContext_->infoEnabled_) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
778 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
779 stream_ = loggingContext_->info_; |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
780 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
781 |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
782 break; |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
783 |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
784 case LogLevel_TRACE: |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
785 if (loggingContext_->traceEnabled_) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
786 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
787 stream_ = loggingContext_->info_; |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
788 } |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
789 |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
790 break; |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
791 |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
792 default: |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
793 throw OrthancException(ErrorCode_InternalError); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
794 } |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
795 |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
796 if (stream_ == &null_) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
797 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
798 // The logging is disabled for this level. The stream is the |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
799 // "null_" member of this object, so we can release the global |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
800 // mutex. |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
801 lock_.unlock(); |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
802 } |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
803 |
4006
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
804 (*stream_) << prefix; |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
805 } |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
806 catch (...) |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
807 { |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
808 // Something is going really wrong, probably running out of |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
809 // memory. Fallback to a degraded mode. |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
810 stream_ = loggingContext_->error_; |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
811 (*stream_) << "E???? ??:??:??.?????? ] "; |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
812 } |
1489 | 813 } |
1507 | 814 |
815 | |
816 InternalLogger::~InternalLogger() | |
817 { | |
818 if (stream_ != &null_) | |
819 { | |
820 *stream_ << "\n"; | |
821 stream_->flush(); | |
822 } | |
823 } | |
824 | |
825 | |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
826 void Flush() |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
827 { |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
828 boost::mutex::scoped_lock lock(loggingMutex_); |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
829 |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
830 if (loggingContext_.get() != NULL && |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
831 loggingContext_->file_.get() != NULL) |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
832 { |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
833 loggingContext_->file_->flush(); |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
834 } |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
835 } |
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
|
836 |
4004
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
837 void SetErrorWarnInfoLoggingStreams(std::ostream& errorStream, |
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
838 std::ostream& warningStream, |
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
839 std::ostream& infoStream) |
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
|
840 { |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
841 std::unique_ptr<LoggingContext> old; |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
842 |
4004
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
843 { |
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
844 boost::mutex::scoped_lock lock(loggingMutex_); |
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
845 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
846 #if __cplusplus < 201103L |
4004
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
847 old.reset(loggingContext_.release()); |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
848 #else |
4004
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
849 old = std::move(loggingContext_); |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
850 #endif |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
851 |
4004
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
852 loggingContext_.reset(new LoggingContext); |
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
853 loggingContext_->error_ = &errorStream; |
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
854 loggingContext_->warning_ = &warningStream; |
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
855 loggingContext_->info_ = &infoStream; |
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
856 } |
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
857 |
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
|
858 EnableInfoLevel(old->infoEnabled_); |
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
|
859 EnableTraceLevel(old->traceEnabled_); |
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
|
860 } |
1485 | 861 } |
862 } | |
1488 | 863 |
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
|
864 |
1489 | 865 #endif // ORTHANC_ENABLE_LOGGING |