Mercurial > hg > orthanc
annotate OrthancFramework/Sources/Logging.cpp @ 4044:d25f4c0fa160 framework
splitting code into OrthancFramework and OrthancServer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 10 Jun 2020 20:30:34 +0200 |
parents | Core/Logging.cpp@05a363186da6 |
children | bf7b9edf6b81 |
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 { |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
99 void InitializePluginContext(void* pluginContext) |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
100 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
101 } |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
102 |
1551
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
103 void Initialize() |
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 } |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
106 |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
107 void Finalize() |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
108 { |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
109 } |
1485 | 110 |
2015
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 Reset() |
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 |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
115 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
|
116 { |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
117 } |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
118 |
1551
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
119 void EnableInfoLevel(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 } |
1489 | 122 |
1551
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
123 void EnableTraceLevel(bool enabled) |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
124 { |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
125 } |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
126 |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
127 bool IsTraceLevelEnabled() |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
128 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
129 return false; |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
130 } |
1551
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
131 |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
132 bool IsInfoLevelEnabled() |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
133 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
134 return false; |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
135 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
136 |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
137 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
|
138 { |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
139 } |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
140 |
1551
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
141 void SetTargetFolder(const std::string& path) |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
142 { |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
143 } |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
144 } |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
145 } |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
146 |
2243
2dbfdafc2512
Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2143
diff
changeset
|
147 |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
148 #elif ORTHANC_ENABLE_LOGGING_STDIO == 1 |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
149 |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
150 /********************************************************* |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
151 * 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
|
152 * 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
|
153 * definition of __EMSCRIPTEN__) |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
154 *********************************************************/ |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
155 |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
156 #include <stdio.h> |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
157 |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
158 #ifdef __EMSCRIPTEN__ |
3506
d2b9981017c4
better handling of HTTP security
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
159 # 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
|
160 #endif |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
161 |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
162 namespace Orthanc |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
163 { |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
164 namespace Logging |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
165 { |
4017
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
166 static bool infoEnabled_ = false; |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
167 static bool traceEnabled_ = false; |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
168 |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
169 #ifdef __EMSCRIPTEN__ |
4010
f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4006
diff
changeset
|
170 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
|
171 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
172 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
|
173 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
174 |
4010
f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4006
diff
changeset
|
175 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
|
176 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
177 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
|
178 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
179 |
4010
f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4006
diff
changeset
|
180 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
|
181 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
182 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
|
183 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
184 |
4010
f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4006
diff
changeset
|
185 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
|
186 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
187 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
|
188 } |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
189 #else /* __EMSCRIPTEN__ not #defined */ |
4010
f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4006
diff
changeset
|
190 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
|
191 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
192 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
|
193 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
194 |
4010
f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4006
diff
changeset
|
195 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
|
196 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
197 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
|
198 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
199 |
4010
f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4006
diff
changeset
|
200 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
|
201 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
202 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
|
203 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
204 |
4010
f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4006
diff
changeset
|
205 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
|
206 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
207 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
|
208 } |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
209 #endif /* __EMSCRIPTEN__ */ |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
210 |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
211 |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
212 InternalLogger::~InternalLogger() |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
213 { |
3489
e7723a39adf8
Fixed alignment issue in Toolbox::DetectEndianness() + made the internal logger
Benjamin Golinvaux <bgo@osimis.io>
parents:
3477
diff
changeset
|
214 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
|
215 |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
216 switch (level_) |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
217 { |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
218 case LogLevel_ERROR: |
4017
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
219 ErrorLogFunc(message.c_str()); |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
220 break; |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
221 |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
222 case LogLevel_WARNING: |
4017
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
223 WarningLogFunc(message.c_str()); |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
224 break; |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
225 |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
226 case LogLevel_INFO: |
4017
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
227 if (infoEnabled_) |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
228 { |
4017
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
229 InfoLogFunc(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
|
230 // TODO: stone_console_info(message_.c_str()); |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
231 } |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
232 break; |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
233 |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
234 case LogLevel_TRACE: |
4017
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
235 if (traceEnabled_) |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
236 { |
4017
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
237 TraceLogFunc(message.c_str()); |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
238 } |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
239 break; |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
240 |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
241 default: |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
242 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
243 std::stringstream ss; |
3489
e7723a39adf8
Fixed alignment issue in Toolbox::DetectEndianness() + made the internal logger
Benjamin Golinvaux <bgo@osimis.io>
parents:
3477
diff
changeset
|
244 ss << "Unknown log level (" << level_ << ") for message: " << message; |
3505
b2d4dd16dae8
removed C++11 primitive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3489
diff
changeset
|
245 std::string s = ss.str(); |
4017
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
246 ErrorLogFunc(s.c_str()); |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
247 } |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
248 } |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
249 } |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
250 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
251 void InitializePluginContext(void* pluginContext) |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
252 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
253 } |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
254 |
3358
849c651c1381
fix missing symbol
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
255 void Initialize() |
849c651c1381
fix missing symbol
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
256 { |
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 |
3995
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
259 void Finalize() |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
260 { |
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 void Reset() |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
264 { |
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 void Flush() |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
268 { |
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 |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
271 void EnableInfoLevel(bool enabled) |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
272 { |
4017
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
273 infoEnabled_ = enabled; |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
274 |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
275 if (!enabled) |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
276 { |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
277 // Also disable the "TRACE" level when info-level debugging is disabled |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
278 traceEnabled_ = false; |
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
279 } |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
280 } |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
281 |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
282 bool IsInfoLevelEnabled() |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
283 { |
4017
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
284 return infoEnabled_; |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
285 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
286 |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
287 void EnableTraceLevel(bool enabled) |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
288 { |
4017
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
289 traceEnabled_ = enabled; |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
290 } |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
291 |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
292 bool IsTraceLevelEnabled() |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
293 { |
4017
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
294 return traceEnabled_; |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
295 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
296 |
3995
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
297 void SetTargetFile(const std::string& path) |
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 void SetTargetFolder(const std::string& path) |
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 } |
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 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
307 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
308 #else |
3995
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
309 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
310 /********************************************************* |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
311 * Logger compatible with the Orthanc plugin SDK, or that |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
312 * mimics behavior from Google Log. |
3995
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 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
315 #include <cassert> |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
316 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
317 namespace |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
318 { |
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 * This is minimal implementation of the context for an Orthanc |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
321 * plugin, limited to the logging facilities, and that is binary |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
322 * compatible with the definitions of "OrthancCPlugin.h" |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
323 **/ |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
324 typedef enum |
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 _OrthancPluginService_LogInfo = 1, |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
327 _OrthancPluginService_LogWarning = 2, |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
328 _OrthancPluginService_LogError = 3, |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
329 _OrthancPluginService_INTERNAL = 0x7fffffff |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
330 } _OrthancPluginService; |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
331 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
332 typedef struct _OrthancPluginContext_t |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
333 { |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
334 void* pluginsManager; |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
335 const char* orthancVersion; |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
336 void (*Free) (void* buffer); |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
337 int32_t (*InvokeService) (struct _OrthancPluginContext_t* context, |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
338 _OrthancPluginService service, |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
339 const void* params); |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
340 } OrthancPluginContext; |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
341 } |
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 |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
344 #include "Enumerations.h" |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
345 #include "SystemToolbox.h" |
1489 | 346 |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
347 #include <fstream> |
1489 | 348 #include <boost/filesystem.hpp> |
349 #include <boost/thread.hpp> | |
2367
2aff870c2c58
refactoring of BoostConfiguration.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2253
diff
changeset
|
350 #include <boost/date_time/posix_time/posix_time.hpp> |
1489 | 351 |
352 | |
353 namespace | |
354 { | |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
355 struct LoggingStreamsContext |
1489 | 356 { |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
357 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
|
358 std::string targetFolder_; |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
359 |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
360 std::ostream* error_; |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
361 std::ostream* warning_; |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
362 std::ostream* info_; |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
363 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
364 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
|
365 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
366 LoggingStreamsContext() : |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
367 error_(&std::cerr), |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
368 warning_(&std::cerr), |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
369 info_(&std::cerr) |
1489 | 370 { |
371 } | |
372 }; | |
373 } | |
374 | |
375 | |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
376 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
377 static std::unique_ptr<LoggingStreamsContext> loggingStreamsContext_; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
378 static boost::mutex loggingStreamsMutex_; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
379 static Orthanc::Logging::NullStream nullStream_; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
380 static OrthancPluginContext* pluginContext_ = NULL; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
381 static bool infoEnabled_ = false; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
382 static bool traceEnabled_ = false; |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
383 |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
384 |
1489 | 385 namespace Orthanc |
386 { | |
387 namespace Logging | |
388 { | |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
389 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
|
390 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
|
391 const std::string& suffix, |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
392 const std::string& directory) |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
393 { |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
394 /** |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
395 From Google Log documentation: |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
396 |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
397 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
|
398 "<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
|
399 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
|
400 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
|
401 |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
402 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
|
403 **/ |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
404 |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
405 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
|
406 boost::filesystem::path root(directory); |
2140 | 407 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
|
408 |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
409 if (!boost::filesystem::exists(root) || |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
410 !boost::filesystem::is_directory(root)) |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
411 { |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
412 throw OrthancException(ErrorCode_CannotWriteFile); |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
413 } |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
414 |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
415 char date[64]; |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
416 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
|
417 static_cast<int>(now.date().year()), |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
418 now.date().month().as_number(), |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
419 now.date().day().as_number(), |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
420 static_cast<int>(now.time_of_day().hours()), |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
421 static_cast<int>(now.time_of_day().minutes()), |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
422 static_cast<int>(now.time_of_day().seconds()), |
2140 | 423 SystemToolbox::GetProcessId()); |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
424 |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
425 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
|
426 |
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
|
427 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
|
428 link = (root / (programName + ".log" + suffix)); |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
429 } |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
430 |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
431 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
432 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
|
433 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
|
434 const std::string& directory) |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
435 { |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
436 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
|
437 GetLogPath(log, link, suffix, directory); |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
438 |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
439 #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
|
440 boost::filesystem::remove(link); |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
441 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
|
442 #endif |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
443 |
1494 | 444 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
|
445 } |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
446 |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
447 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
448 // "loggingStreamsMutex_" must be locked |
4006
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
449 static void CheckFile(std::unique_ptr<std::ofstream>& f) |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
450 { |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
451 if (loggingStreamsContext_->file_.get() == NULL || |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
452 !loggingStreamsContext_->file_->is_open()) |
4006
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
453 { |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
454 throw OrthancException(ErrorCode_CannotWriteFile); |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
455 } |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
456 } |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
457 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
458 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
459 static void GetLinePrefix(std::string& prefix, |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
460 LogLevel level, |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
461 const char* file, |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
462 int line) |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
463 { |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
464 boost::filesystem::path path(file); |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
465 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
|
466 boost::posix_time::time_duration duration = now.time_of_day(); |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
467 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
468 /** |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
469 From Google Log documentation: |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
470 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
471 "Log lines have this form: |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
472 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
473 Lmmdd hh:mm:ss.uuuuuu threadid file:line] msg... |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
474 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
475 where the fields are defined as follows: |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
476 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
477 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
|
478 mm The month (zero padded; ie May is '05') |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
479 dd The day (zero padded) |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
480 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
|
481 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
|
482 file The file name |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
483 line The line number |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
484 msg The user-supplied message" |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
485 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
486 In this implementation, "threadid" is not printed. |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
487 **/ |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
488 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
489 char c; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
490 switch (level) |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
491 { |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
492 case LogLevel_ERROR: |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
493 c = 'E'; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
494 break; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
495 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
496 case LogLevel_WARNING: |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
497 c = 'W'; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
498 break; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
499 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
500 case LogLevel_INFO: |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
501 c = 'I'; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
502 break; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
503 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
504 case LogLevel_TRACE: |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
505 c = 'T'; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
506 break; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
507 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
508 default: |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
509 throw OrthancException(ErrorCode_InternalError); |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
510 } |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
511 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
512 char date[64]; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
513 sprintf(date, "%c%02d%02d %02d:%02d:%02d.%06d ", |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
514 c, |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
515 now.date().month().as_number(), |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
516 now.date().day().as_number(), |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
517 static_cast<int>(duration.hours()), |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
518 static_cast<int>(duration.minutes()), |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
519 static_cast<int>(duration.seconds()), |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
520 static_cast<int>(duration.fractional_seconds())); |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
521 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
522 prefix = (std::string(date) + path.filename().string() + ":" + |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
523 boost::lexical_cast<std::string>(line) + "] "); |
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 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
527 void InitializePluginContext(void* pluginContext) |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
528 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
529 assert(sizeof(_OrthancPluginService) == sizeof(int32_t)); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
530 |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
531 boost::mutex::scoped_lock lock(loggingStreamsMutex_); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
532 loggingStreamsContext_.reset(NULL); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
533 pluginContext_ = reinterpret_cast<OrthancPluginContext*>(pluginContext); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
534 } |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
535 |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
536 |
1489 | 537 void Initialize() |
538 { | |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
539 boost::mutex::scoped_lock lock(loggingStreamsMutex_); |
4026
05a363186da6
ORTHANC_BUILDING_FRAMEWORK_LIBRARY, Orthanc::InitializeFramework()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4017
diff
changeset
|
540 |
05a363186da6
ORTHANC_BUILDING_FRAMEWORK_LIBRARY, Orthanc::InitializeFramework()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4017
diff
changeset
|
541 if (loggingStreamsContext_.get() == NULL) |
05a363186da6
ORTHANC_BUILDING_FRAMEWORK_LIBRARY, Orthanc::InitializeFramework()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4017
diff
changeset
|
542 { |
05a363186da6
ORTHANC_BUILDING_FRAMEWORK_LIBRARY, Orthanc::InitializeFramework()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4017
diff
changeset
|
543 loggingStreamsContext_.reset(new LoggingStreamsContext); |
05a363186da6
ORTHANC_BUILDING_FRAMEWORK_LIBRARY, Orthanc::InitializeFramework()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4017
diff
changeset
|
544 } |
1489 | 545 } |
546 | |
547 void Finalize() | |
548 { | |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
549 boost::mutex::scoped_lock lock(loggingStreamsMutex_); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
550 loggingStreamsContext_.reset(NULL); |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
551 } |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
552 |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
553 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
|
554 { |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
555 // Recover the old logging context |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
556 std::unique_ptr<LoggingStreamsContext> 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
|
557 |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
558 { |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
559 boost::mutex::scoped_lock lock(loggingStreamsMutex_); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
560 if (loggingStreamsContext_.get() == NULL) |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
561 { |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
562 return; |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
563 } |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
564 else |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
565 { |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
566 #if __cplusplus < 201103L |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
567 old.reset(loggingStreamsContext_.release()); |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
568 #else |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
569 old = std::move(loggingStreamsContext_); |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
570 #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
|
571 |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
572 // Create a new logging context, |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
573 loggingStreamsContext_.reset(new LoggingStreamsContext); |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
574 } |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
575 } |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
576 |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
577 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
|
578 { |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
579 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
|
580 } |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
581 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
|
582 { |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
583 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
|
584 } |
1489 | 585 } |
586 | |
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
|
587 |
1489 | 588 void EnableInfoLevel(bool enabled) |
589 { | |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
590 infoEnabled_ = 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
|
591 |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
592 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
|
593 { |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
594 // Also disable the "TRACE" level when info-level debugging is disabled |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
595 traceEnabled_ = false; |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
596 } |
1489 | 597 } |
598 | |
3629
19966d299685
Fixed typo in function impl name
Benjamin Golinvaux <bgo@osimis.io>
parents:
3506
diff
changeset
|
599 bool IsInfoLevelEnabled() |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
600 { |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
601 return infoEnabled_; |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
602 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
603 |
1489 | 604 void EnableTraceLevel(bool enabled) |
605 { | |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
606 traceEnabled_ = enabled; |
1489 | 607 |
608 if (enabled) | |
609 { | |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
610 // Also enable the "INFO" level when trace-level debugging is enabled |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
611 infoEnabled_ = true; |
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 |
3629
19966d299685
Fixed typo in function impl name
Benjamin Golinvaux <bgo@osimis.io>
parents:
3506
diff
changeset
|
615 bool IsTraceLevelEnabled() |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
616 { |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
617 return traceEnabled_; |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
618 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
619 |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
620 |
1489 | 621 void SetTargetFolder(const std::string& path) |
622 { | |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
623 boost::mutex::scoped_lock lock(loggingStreamsMutex_); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
624 if (loggingStreamsContext_.get() != NULL) |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
625 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
626 PrepareLogFolder(loggingStreamsContext_->file_, "" /* no suffix */, path); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
627 CheckFile(loggingStreamsContext_->file_); |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
628 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
629 loggingStreamsContext_->targetFile_.clear(); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
630 loggingStreamsContext_->targetFolder_ = path; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
631 loggingStreamsContext_->warning_ = loggingStreamsContext_->file_.get(); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
632 loggingStreamsContext_->error_ = loggingStreamsContext_->file_.get(); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
633 loggingStreamsContext_->info_ = loggingStreamsContext_->file_.get(); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
634 } |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
635 } |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
636 |
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
|
637 |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
638 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
|
639 { |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
640 boost::mutex::scoped_lock lock(loggingStreamsMutex_); |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
641 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
642 if (loggingStreamsContext_.get() != NULL) |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
643 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
644 loggingStreamsContext_->file_.reset(new std::ofstream(path.c_str(), std::fstream::app)); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
645 CheckFile(loggingStreamsContext_->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
|
646 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
647 loggingStreamsContext_->targetFile_ = path; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
648 loggingStreamsContext_->targetFolder_.clear(); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
649 loggingStreamsContext_->warning_ = loggingStreamsContext_->file_.get(); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
650 loggingStreamsContext_->error_ = loggingStreamsContext_->file_.get(); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
651 loggingStreamsContext_->info_ = loggingStreamsContext_->file_.get(); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
652 } |
1489 | 653 } |
654 | |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
655 |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
656 InternalLogger::InternalLogger(LogLevel level, |
1489 | 657 const char* file, |
658 int line) : | |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
659 lock_(loggingStreamsMutex_, boost::defer_lock_t()), |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
660 level_(level), |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
661 stream_(&nullStream_) // By default, logging to "/dev/null" is simulated |
1489 | 662 { |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
663 if (pluginContext_ != NULL) |
1489 | 664 { |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
665 // We are logging using the Orthanc plugin SDK |
1489 | 666 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
667 if (level == LogLevel_TRACE) |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
668 { |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
669 // No trace level in plugins, directly exit as the stream is |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
670 // set to "/dev/null" |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
671 return; |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
672 } |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
673 else |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
674 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
675 pluginStream_.reset(new std::stringstream); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
676 stream_ = pluginStream_.get(); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
677 } |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
678 } |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
679 else |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
680 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
681 // We are logging in a standalone application, not inside an Orthanc plugin |
1489 | 682 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
683 if ((level == LogLevel_INFO && !infoEnabled_) || |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
684 (level == LogLevel_TRACE && !traceEnabled_)) |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
685 { |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
686 // This logging level is disabled, directly exit as the |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
687 // stream is set to "/dev/null" |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
688 return; |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
689 } |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
690 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
691 std::string prefix; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
692 GetLinePrefix(prefix, level, file, line); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
693 |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
694 { |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
695 // We lock the global mutex. The mutex is locked until the |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
696 // destructor is called: No change in the output can be done. |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
697 lock_.lock(); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
698 |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
699 if (loggingStreamsContext_.get() == NULL) |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
700 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
701 fprintf(stderr, "ERROR: Trying to log a message after the finalization of the logging engine\n"); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
702 lock_.unlock(); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
703 return; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
704 } |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
705 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
706 switch (level) |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
707 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
708 case LogLevel_ERROR: |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
709 stream_ = loggingStreamsContext_->error_; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
710 break; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
711 |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
712 case LogLevel_WARNING: |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
713 stream_ = loggingStreamsContext_->warning_; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
714 break; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
715 |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
716 case LogLevel_INFO: |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
717 case LogLevel_TRACE: |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
718 stream_ = loggingStreamsContext_->info_; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
719 break; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
720 |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
721 default: |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
722 throw OrthancException(ErrorCode_InternalError); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
723 } |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
724 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
725 if (stream_ == &nullStream_) |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
726 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
727 // The logging is disabled for this level, we can release |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
728 // the global mutex. |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
729 lock_.unlock(); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
730 } |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
731 else |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
732 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
733 try |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
734 { |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
735 (*stream_) << prefix; |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
736 } |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
737 catch (...) |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
738 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
739 // Something is going really wrong, probably running out of |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
740 // memory. Fallback to a degraded mode. |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
741 stream_ = loggingStreamsContext_->error_; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
742 (*stream_) << "E???? ??:??:??.?????? ] "; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
743 } |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
744 } |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
745 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
746 } |
1489 | 747 } |
1507 | 748 |
749 | |
750 InternalLogger::~InternalLogger() | |
751 { | |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
752 if (pluginStream_.get() != NULL) |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
753 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
754 // We are logging through the Orthanc SDK |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
755 |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
756 std::string message = pluginStream_->str(); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
757 |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
758 if (pluginContext_ != NULL) |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
759 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
760 switch (level_) |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
761 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
762 case LogLevel_ERROR: |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
763 pluginContext_->InvokeService(pluginContext_, _OrthancPluginService_LogError, message.c_str()); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
764 break; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
765 |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
766 case LogLevel_WARNING: |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
767 pluginContext_->InvokeService(pluginContext_, _OrthancPluginService_LogWarning, message.c_str()); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
768 break; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
769 |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
770 case LogLevel_INFO: |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
771 pluginContext_->InvokeService(pluginContext_, _OrthancPluginService_LogInfo, message.c_str()); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
772 break; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
773 |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
774 default: |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
775 break; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
776 } |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
777 } |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
778 } |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
779 else if (stream_ != &nullStream_) |
1507 | 780 { |
781 *stream_ << "\n"; | |
782 stream_->flush(); | |
783 } | |
784 } | |
785 | |
786 | |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
787 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
|
788 { |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
789 if (pluginContext_ != NULL) |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
790 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
791 boost::mutex::scoped_lock lock(loggingStreamsMutex_); |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
792 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
793 if (loggingStreamsContext_.get() != NULL && |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
794 loggingStreamsContext_->file_.get() != NULL) |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
795 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
796 loggingStreamsContext_->file_->flush(); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
797 } |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
798 } |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
799 } |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
800 |
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
|
801 |
4004
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
802 void SetErrorWarnInfoLoggingStreams(std::ostream& errorStream, |
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
803 std::ostream& warningStream, |
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
804 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
|
805 { |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
806 boost::mutex::scoped_lock lock(loggingStreamsMutex_); |
4004
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
807 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
808 loggingStreamsContext_.reset(new LoggingStreamsContext); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
809 loggingStreamsContext_->error_ = &errorStream; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
810 loggingStreamsContext_->warning_ = &warningStream; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
811 loggingStreamsContext_->info_ = &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
|
812 } |
1485 | 813 } |
814 } | |
1488 | 815 |
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
|
816 |
1489 | 817 #endif // ORTHANC_ENABLE_LOGGING |