Mercurial > hg > orthanc
annotate OrthancFramework/Sources/Logging.cpp @ 5476:3b45bce71fcc
Orthanc Framework 1.12.2
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 19 Dec 2023 11:45:37 +0100 |
parents | 67dc2567ea6f |
children | 48b8dae6dc77 |
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 |
5185
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5031
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5031
diff
changeset
|
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1485 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
11 * the License, or (at your option) any later version. |
1485 | 12 * |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
16 * Lesser General Public License for more details. |
1485 | 17 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
19 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
1485 | 21 **/ |
22 | |
23 | |
24 #include "PrecompiledHeaders.h" | |
25 #include "Logging.h" | |
26 | |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
27 #include "OrthancException.h" |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
28 |
4306 | 29 #include <stdint.h> |
30 | |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
31 |
4269
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
32 /********************************************************* |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
33 * Common section |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
34 *********************************************************/ |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
35 |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
36 namespace Orthanc |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
37 { |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
38 namespace Logging |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
39 { |
4270
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
40 static const uint32_t ALL_CATEGORIES_MASK = 0xffffffff; |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
41 |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
42 static uint32_t infoCategoriesMask_ = 0; |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
43 static uint32_t traceCategoriesMask_ = 0; |
4317
a691916ab535
fix for 'logs are not stored in log files anymore after a /tools/reset'
Alain Mazy <alain@mazy.be>
parents:
4306
diff
changeset
|
44 static std::string logTargetFolder_; // keep a track of the log folder in case of reset of the context |
a691916ab535
fix for 'logs are not stored in log files anymore after a /tools/reset'
Alain Mazy <alain@mazy.be>
parents:
4306
diff
changeset
|
45 static std::string logTargetFile_; // keep a track of the log file in case of reset of the context |
4269
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
46 |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
47 const char* EnumerationToString(LogLevel level) |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
48 { |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
49 switch (level) |
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_ERROR: |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
52 return "ERROR"; |
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_WARNING: |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
55 return "WARNING"; |
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_INFO: |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
58 return "INFO"; |
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 case LogLevel_TRACE: |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
61 return "TRACE"; |
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 default: |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
64 throw OrthancException(ErrorCode_ParameterOutOfRange); |
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 } |
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 |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
69 LogLevel StringToLogLevel(const char *level) |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
70 { |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
71 if (strcmp(level, "ERROR") == 0) |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
72 { |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
73 return LogLevel_ERROR; |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
74 } |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
75 else if (strcmp(level, "WARNING") == 0) |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
76 { |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
77 return LogLevel_WARNING; |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
78 } |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
79 else if (strcmp(level, "INFO") == 0) |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
80 { |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
81 return LogLevel_INFO; |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
82 } |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
83 else if (strcmp(level, "TRACE") == 0) |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
84 { |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
85 return LogLevel_TRACE; |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
86 } |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
87 else |
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 throw OrthancException(ErrorCode_InternalError); |
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 } |
4269
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
92 |
4270
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
93 |
4269
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
94 void EnableInfoLevel(bool enabled) |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
95 { |
4270
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
96 if (enabled) |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
97 { |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
98 infoCategoriesMask_ = ALL_CATEGORIES_MASK; |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
99 } |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
100 else |
4269
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
101 { |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
102 // Also disable the "TRACE" level when info-level debugging is disabled |
4270
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
103 infoCategoriesMask_ = 0; |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
104 traceCategoriesMask_ = 0; |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
105 } |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
106 } |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
107 |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
108 |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
109 bool IsInfoLevelEnabled() |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
110 { |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
111 return (infoCategoriesMask_ != 0); |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
112 } |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
113 |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
114 |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
115 void EnableTraceLevel(bool enabled) |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
116 { |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
117 if (enabled) |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
118 { |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
119 // Also enable the "INFO" level when trace-level debugging is enabled |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
120 infoCategoriesMask_ = ALL_CATEGORIES_MASK; |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
121 traceCategoriesMask_ = ALL_CATEGORIES_MASK; |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
122 } |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
123 else |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
124 { |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
125 traceCategoriesMask_ = 0; |
4269
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
126 } |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
127 } |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
128 |
4270
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
129 |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
130 bool IsTraceLevelEnabled() |
4269
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
131 { |
4270
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
132 return (traceCategoriesMask_ != 0); |
4269
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
133 } |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
134 |
4270
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
135 |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
136 void SetCategoryEnabled(LogLevel level, |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
137 LogCategory category, |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
138 bool enabled) |
4269
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
139 { |
4271
1bd14c900699
LogCategory_PLUGINS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4270
diff
changeset
|
140 // Invariant: If a bit is set for "trace", it must also be set |
1bd14c900699
LogCategory_PLUGINS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4270
diff
changeset
|
141 // for "verbose" (in other words, trace level implies verbose level) |
1bd14c900699
LogCategory_PLUGINS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4270
diff
changeset
|
142 assert((traceCategoriesMask_ & infoCategoriesMask_) == traceCategoriesMask_); |
1bd14c900699
LogCategory_PLUGINS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4270
diff
changeset
|
143 |
4270
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
144 if (level == LogLevel_INFO) |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
145 { |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
146 if (enabled) |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
147 { |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
148 infoCategoriesMask_ |= static_cast<uint32_t>(category); |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
149 } |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
150 else |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
151 { |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
152 infoCategoriesMask_ &= ~static_cast<uint32_t>(category); |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
153 traceCategoriesMask_ &= ~static_cast<uint32_t>(category); |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
154 } |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
155 } |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
156 else if (level == LogLevel_TRACE) |
4269
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
157 { |
4270
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
158 if (enabled) |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
159 { |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
160 traceCategoriesMask_ |= static_cast<uint32_t>(category); |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
161 infoCategoriesMask_ |= static_cast<uint32_t>(category); |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
162 } |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
163 else |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
164 { |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
165 traceCategoriesMask_ &= ~static_cast<uint32_t>(category); |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
166 } |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
167 } |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
168 else |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
169 { |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
170 throw OrthancException(ErrorCode_ParameterOutOfRange, |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
171 "Can only modify the parameters of the INFO and TRACE levels"); |
4269
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
172 } |
4271
1bd14c900699
LogCategory_PLUGINS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4270
diff
changeset
|
173 |
1bd14c900699
LogCategory_PLUGINS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4270
diff
changeset
|
174 assert((traceCategoriesMask_ & infoCategoriesMask_) == traceCategoriesMask_); |
4269
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
175 } |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
176 |
4270
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
177 |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
178 bool IsCategoryEnabled(LogLevel level, |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
179 LogCategory category) |
4269
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
180 { |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
181 if (level == LogLevel_ERROR || |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
182 level == LogLevel_WARNING) |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
183 { |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
184 return true; |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
185 } |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
186 else if (level == LogLevel_INFO) |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
187 { |
4270
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
188 return (infoCategoriesMask_ & category) != 0; |
4269
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
189 } |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
190 else if (level == LogLevel_TRACE) |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
191 { |
4270
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
192 return (traceCategoriesMask_ & category) != 0; |
4269
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
193 } |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
194 else |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
195 { |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
196 return false; |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
197 } |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
198 } |
4270
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
199 |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
200 |
4273
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
201 bool LookupCategory(LogCategory& target, |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
202 const std::string& category) |
4270
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
203 { |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
204 if (category == "generic") |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
205 { |
4273
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
206 target = LogCategory_GENERIC; |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
207 return true; |
4270
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
208 } |
4271
1bd14c900699
LogCategory_PLUGINS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4270
diff
changeset
|
209 else if (category == "plugins") |
1bd14c900699
LogCategory_PLUGINS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4270
diff
changeset
|
210 { |
4273
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
211 target = LogCategory_PLUGINS; |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
212 return true; |
4271
1bd14c900699
LogCategory_PLUGINS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4270
diff
changeset
|
213 } |
4294
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4293
diff
changeset
|
214 else if (category == "http") |
4272 | 215 { |
4294
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4293
diff
changeset
|
216 target = LogCategory_HTTP; |
4273
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
217 return true; |
4272 | 218 } |
4270
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
219 else if (category == "dicom") |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
220 { |
4273
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
221 target = LogCategory_DICOM; |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
222 return true; |
4270
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
223 } |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
224 else if (category == "sqlite") |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
225 { |
4273
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
226 target = LogCategory_SQLITE; |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
227 return true; |
4270
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
228 } |
4294
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4293
diff
changeset
|
229 else if (category == "jobs") |
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4293
diff
changeset
|
230 { |
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4293
diff
changeset
|
231 target = LogCategory_JOBS; |
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4293
diff
changeset
|
232 return true; |
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4293
diff
changeset
|
233 } |
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4293
diff
changeset
|
234 else if (category == "lua") |
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4293
diff
changeset
|
235 { |
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4293
diff
changeset
|
236 target = LogCategory_LUA; |
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4293
diff
changeset
|
237 return true; |
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4293
diff
changeset
|
238 } |
4270
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
239 else |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
240 { |
4273
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
241 return false; |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
242 } |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
243 } |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
244 |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
245 |
4275
d7a50b7b8466
Dynamically access and/or change the verbosity of logging categories with the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
246 unsigned int GetCategoriesCount() |
4273
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
247 { |
4294
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4293
diff
changeset
|
248 return 7; |
4273
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
249 } |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
250 |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
251 |
4275
d7a50b7b8466
Dynamically access and/or change the verbosity of logging categories with the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
252 const char* GetCategoryName(unsigned int i) |
4273
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
253 { |
4275
d7a50b7b8466
Dynamically access and/or change the verbosity of logging categories with the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
254 if (i < GetCategoriesCount()) |
d7a50b7b8466
Dynamically access and/or change the verbosity of logging categories with the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
255 { |
d7a50b7b8466
Dynamically access and/or change the verbosity of logging categories with the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
256 return GetCategoryName(static_cast<LogCategory>(1 << i)); |
d7a50b7b8466
Dynamically access and/or change the verbosity of logging categories with the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
257 } |
d7a50b7b8466
Dynamically access and/or change the verbosity of logging categories with the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
258 else |
4273
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
259 { |
4275
d7a50b7b8466
Dynamically access and/or change the verbosity of logging categories with the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
260 throw OrthancException(ErrorCode_ParameterOutOfRange); |
d7a50b7b8466
Dynamically access and/or change the verbosity of logging categories with the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
261 } |
d7a50b7b8466
Dynamically access and/or change the verbosity of logging categories with the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
262 } |
d7a50b7b8466
Dynamically access and/or change the verbosity of logging categories with the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
263 |
d7a50b7b8466
Dynamically access and/or change the verbosity of logging categories with the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
264 |
d7a50b7b8466
Dynamically access and/or change the verbosity of logging categories with the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
265 const char* GetCategoryName(LogCategory category) |
d7a50b7b8466
Dynamically access and/or change the verbosity of logging categories with the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
266 { |
d7a50b7b8466
Dynamically access and/or change the verbosity of logging categories with the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
267 switch (category) |
d7a50b7b8466
Dynamically access and/or change the verbosity of logging categories with the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
268 { |
d7a50b7b8466
Dynamically access and/or change the verbosity of logging categories with the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
269 case LogCategory_GENERIC: |
4273
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
270 return "generic"; |
4275
d7a50b7b8466
Dynamically access and/or change the verbosity of logging categories with the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
271 |
d7a50b7b8466
Dynamically access and/or change the verbosity of logging categories with the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
272 case LogCategory_PLUGINS: |
4273
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
273 return "plugins"; |
4275
d7a50b7b8466
Dynamically access and/or change the verbosity of logging categories with the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
274 |
4294
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4293
diff
changeset
|
275 case LogCategory_HTTP: |
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4293
diff
changeset
|
276 return "http"; |
4275
d7a50b7b8466
Dynamically access and/or change the verbosity of logging categories with the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
277 |
d7a50b7b8466
Dynamically access and/or change the verbosity of logging categories with the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
278 case LogCategory_DICOM: |
4273
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
279 return "dicom"; |
4275
d7a50b7b8466
Dynamically access and/or change the verbosity of logging categories with the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
280 |
d7a50b7b8466
Dynamically access and/or change the verbosity of logging categories with the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4273
diff
changeset
|
281 case LogCategory_SQLITE: |
4273
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
282 return "sqlite"; |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
283 |
4294
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4293
diff
changeset
|
284 case LogCategory_JOBS: |
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4293
diff
changeset
|
285 return "jobs"; |
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4293
diff
changeset
|
286 |
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4293
diff
changeset
|
287 case LogCategory_LUA: |
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4293
diff
changeset
|
288 return "lua"; |
0923247e69f6
log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents:
4293
diff
changeset
|
289 |
4273
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
290 default: |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
291 throw OrthancException(ErrorCode_ParameterOutOfRange); |
4270
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
292 } |
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
293 } |
3998
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
294 } |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
295 } |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
296 |
b3f09bc9734b
sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3996
diff
changeset
|
297 |
4269
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
298 |
1551
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
299 #if ORTHANC_ENABLE_LOGGING != 1 |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
300 |
4269
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
301 /********************************************************* |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
302 * Section if logging is disabled |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
303 *********************************************************/ |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
304 |
1551
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
305 namespace Orthanc |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
306 { |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
307 namespace Logging |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
308 { |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
309 void InitializePluginContext(void* pluginContext) |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
310 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
311 } |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
312 |
1551
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
313 void Initialize() |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
314 { |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
315 } |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
316 |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
317 void Finalize() |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
318 { |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
319 } |
1485 | 320 |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
321 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
|
322 { |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
323 } |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
324 |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
325 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
|
326 { |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
327 } |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
328 |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
329 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
|
330 { |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
331 } |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
332 |
1551
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
333 void SetTargetFolder(const std::string& path) |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
334 { |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
335 } |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
336 } |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
337 } |
0dba274074eb
standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1507
diff
changeset
|
338 |
2243
2dbfdafc2512
Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2143
diff
changeset
|
339 |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
340 #elif ORTHANC_ENABLE_LOGGING_STDIO == 1 |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
341 |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
342 /********************************************************* |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
343 * 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
|
344 * 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
|
345 * definition of __EMSCRIPTEN__) |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
346 *********************************************************/ |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
347 |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
348 #include <stdio.h> |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
349 |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
350 #ifdef __EMSCRIPTEN__ |
3506
d2b9981017c4
better handling of HTTP security
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3505
diff
changeset
|
351 # 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
|
352 #endif |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
353 |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
354 namespace Orthanc |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
355 { |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
356 namespace Logging |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
357 { |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
358 #ifdef __EMSCRIPTEN__ |
4010
f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4006
diff
changeset
|
359 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
|
360 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
361 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
|
362 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
363 |
4010
f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4006
diff
changeset
|
364 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
|
365 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
366 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
|
367 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
368 |
4010
f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4006
diff
changeset
|
369 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
|
370 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
371 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
|
372 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
373 |
4010
f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4006
diff
changeset
|
374 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
|
375 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
376 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
|
377 } |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
378 #else /* __EMSCRIPTEN__ not #defined */ |
4010
f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4006
diff
changeset
|
379 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
|
380 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
381 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
|
382 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
383 |
4010
f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4006
diff
changeset
|
384 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
|
385 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
386 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
|
387 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
388 |
4010
f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4006
diff
changeset
|
389 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
|
390 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
391 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
|
392 } |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
393 |
4010
f0ee3f1db775
removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4006
diff
changeset
|
394 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
|
395 { |
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
396 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
|
397 } |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
398 #endif /* __EMSCRIPTEN__ */ |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
399 |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
400 |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
401 InternalLogger::~InternalLogger() |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
402 { |
3489
e7723a39adf8
Fixed alignment issue in Toolbox::DetectEndianness() + made the internal logger
Benjamin Golinvaux <bgo@osimis.io>
parents:
3477
diff
changeset
|
403 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
|
404 |
4270
251a8b07fa37
logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4269
diff
changeset
|
405 if (IsCategoryEnabled(level_, category_)) |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
406 { |
4269
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
407 switch (level_) |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
408 { |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
409 case LogLevel_ERROR: |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
410 ErrorLogFunc(message.c_str()); |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
411 break; |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
412 |
4269
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
413 case LogLevel_WARNING: |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
414 WarningLogFunc(message.c_str()); |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
415 break; |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
416 |
4269
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
417 case LogLevel_INFO: |
4017
c783f4f29390
log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4014
diff
changeset
|
418 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
|
419 // TODO: stone_console_info(message_.c_str()); |
4269
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
420 break; |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
421 |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
422 case LogLevel_TRACE: |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
423 TraceLogFunc(message.c_str()); |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
424 break; |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
425 |
4269
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
426 default: |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
427 { |
4269
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
428 std::stringstream ss; |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
429 ss << "Unknown log level (" << level_ << ") for message: " << message; |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
430 std::string s = ss.str(); |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
431 ErrorLogFunc(s.c_str()); |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
432 } |
3359
815b81142ff7
Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents:
3353
diff
changeset
|
433 } |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
434 } |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
435 } |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
436 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
437 void InitializePluginContext(void* pluginContext) |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
438 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
439 } |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
440 |
3358
849c651c1381
fix missing symbol
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
441 void Initialize() |
849c651c1381
fix missing symbol
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
442 { |
849c651c1381
fix missing symbol
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
443 } |
849c651c1381
fix missing symbol
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
444 |
3995
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
445 void Finalize() |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
446 { |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
447 } |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
448 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
449 void Reset() |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
450 { |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
451 } |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
452 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
453 void Flush() |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
454 { |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
455 } |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
456 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
457 void SetTargetFile(const std::string& path) |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
458 { |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
459 } |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
460 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
461 void SetTargetFolder(const std::string& path) |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
462 { |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
463 } |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
464 } |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
465 } |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
466 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
467 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
468 #else |
3995
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
469 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
470 /********************************************************* |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
471 * 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
|
472 * mimics behavior from Google Log. |
3995
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
473 *********************************************************/ |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
474 |
5461
67dc2567ea6f
fix compatibility with WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5452
diff
changeset
|
475 #include <boost/thread/thread.hpp> |
3995
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
476 #include <cassert> |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
477 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
478 namespace |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
479 { |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
480 /** |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
481 * This is minimal implementation of the context for an Orthanc |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
482 * plugin, limited to the logging facilities, and that is binary |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
483 * compatible with the definitions of "OrthancCPlugin.h" |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
484 **/ |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
485 typedef enum |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
486 { |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
487 _OrthancPluginService_LogInfo = 1, |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
488 _OrthancPluginService_LogWarning = 2, |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
489 _OrthancPluginService_LogError = 3, |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
490 _OrthancPluginService_INTERNAL = 0x7fffffff |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
491 } _OrthancPluginService; |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
492 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
493 typedef struct _OrthancPluginContext_t |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
494 { |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
495 void* pluginsManager; |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
496 const char* orthancVersion; |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
497 void (*Free) (void* buffer); |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
498 int32_t (*InvokeService) (struct _OrthancPluginContext_t* context, |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
499 _OrthancPluginService service, |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
500 const void* params); |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
501 } OrthancPluginContext; |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
502 } |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
503 |
1f405a3fdeca
reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3712
diff
changeset
|
504 |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
505 #include "Enumerations.h" |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
506 #include "SystemToolbox.h" |
1489 | 507 |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
508 #include <fstream> |
1489 | 509 #include <boost/filesystem.hpp> |
510 #include <boost/thread.hpp> | |
2367
2aff870c2c58
refactoring of BoostConfiguration.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2253
diff
changeset
|
511 #include <boost/date_time/posix_time/posix_time.hpp> |
1489 | 512 |
513 | |
514 namespace | |
515 { | |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
516 struct LoggingStreamsContext |
1489 | 517 { |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
518 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
|
519 std::string targetFolder_; |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
520 |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
521 std::ostream* error_; |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
522 std::ostream* warning_; |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
523 std::ostream* info_; |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
524 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
525 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
|
526 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
527 LoggingStreamsContext() : |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
528 error_(&std::cerr), |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
529 warning_(&std::cerr), |
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
530 info_(&std::cerr) |
1489 | 531 { |
532 } | |
533 }; | |
534 } | |
535 | |
536 | |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
537 |
5450
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
538 static std::unique_ptr<LoggingStreamsContext> loggingStreamsContext_; |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
539 static boost::mutex loggingStreamsMutex_; |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
540 static Orthanc::Logging::NullStream nullStream_; |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
541 static OrthancPluginContext* pluginContext_ = NULL; |
5452
8345267e8de5
Added OrthancPluginSetCurrentThreadName() in the plugin SDK
Alain Mazy <am@osimis.io>
parents:
5450
diff
changeset
|
542 static boost::recursive_mutex threadNamesMutex_; |
5450
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
543 static std::map<boost::thread::id, std::string> threadNames_; |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
544 static bool enableThreadNames_ = true; |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
545 |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
546 |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
547 |
1489 | 548 namespace Orthanc |
549 { | |
550 namespace Logging | |
551 { | |
5450
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
552 void EnableThreadNames(bool enabled) |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
553 { |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
554 enableThreadNames_ = enabled; |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
555 } |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
556 |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
557 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
|
558 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
|
559 const std::string& suffix, |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
560 const std::string& directory) |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
561 { |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
562 /** |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
563 From Google Log documentation: |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
564 |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
565 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
|
566 "<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
|
567 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
|
568 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
|
569 |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
570 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
|
571 **/ |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
572 |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
573 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
|
574 boost::filesystem::path root(directory); |
2140 | 575 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
|
576 |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
577 if (!boost::filesystem::exists(root) || |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
578 !boost::filesystem::is_directory(root)) |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
579 { |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
580 throw OrthancException(ErrorCode_CannotWriteFile); |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
581 } |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
582 |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
583 char date[64]; |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
584 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
|
585 static_cast<int>(now.date().year()), |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
586 now.date().month().as_number(), |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
587 now.date().day().as_number(), |
2483
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
588 static_cast<int>(now.time_of_day().hours()), |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
589 static_cast<int>(now.time_of_day().minutes()), |
9c54c40eaf25
logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
590 static_cast<int>(now.time_of_day().seconds()), |
2140 | 591 SystemToolbox::GetProcessId()); |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
592 |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
593 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
|
594 |
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
|
595 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
|
596 link = (root / (programName + ".log" + suffix)); |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
597 } |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
598 |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
599 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
600 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
|
601 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
|
602 const std::string& directory) |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
603 { |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
604 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
|
605 GetLogPath(log, link, suffix, directory); |
1490
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
606 |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
607 #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
|
608 boost::filesystem::remove(link); |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
609 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
|
610 #endif |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
611 |
1494 | 612 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
|
613 } |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
614 |
596927722403
support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1489
diff
changeset
|
615 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
616 // "loggingStreamsMutex_" must be locked |
4006
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
617 static void CheckFile(std::unique_ptr<std::ofstream>& f) |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
618 { |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
619 if (loggingStreamsContext_->file_.get() == NULL || |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
620 !loggingStreamsContext_->file_->is_open()) |
4006
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
621 { |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
622 throw OrthancException(ErrorCode_CannotWriteFile); |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
623 } |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
624 } |
5450
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
625 |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
626 void SetCurrentThreadNameInternal(const boost::thread::id& id, const std::string& name) |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
627 { |
5452
8345267e8de5
Added OrthancPluginSetCurrentThreadName() in the plugin SDK
Alain Mazy <am@osimis.io>
parents:
5450
diff
changeset
|
628 boost::recursive_mutex::scoped_lock lock(threadNamesMutex_); |
8345267e8de5
Added OrthancPluginSetCurrentThreadName() in the plugin SDK
Alain Mazy <am@osimis.io>
parents:
5450
diff
changeset
|
629 |
5450
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
630 if (name.size() > 16) |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
631 { |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
632 throw OrthancException(ErrorCode_InternalError, std::string("Thread name can not exceed 16 characters: ") + name); |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
633 } |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
634 |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
635 threadNames_[id] = name; |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
636 } |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
637 |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
638 void SetCurrentThreadName(const std::string& name) |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
639 { |
5452
8345267e8de5
Added OrthancPluginSetCurrentThreadName() in the plugin SDK
Alain Mazy <am@osimis.io>
parents:
5450
diff
changeset
|
640 boost::recursive_mutex::scoped_lock lock(threadNamesMutex_); |
5450
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
641 SetCurrentThreadNameInternal(boost::this_thread::get_id(), name); |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
642 } |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
643 |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
644 bool HasCurrentThreadName() |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
645 { |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
646 boost::thread::id threadId = boost::this_thread::get_id(); |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
647 |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
648 boost::mutex::scoped_lock lock(loggingStreamsMutex_); |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
649 return threadNames_.find(threadId) != threadNames_.end(); |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
650 } |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
651 |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
652 static std::string GetCurrentThreadName() |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
653 { |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
654 boost::thread::id threadId = boost::this_thread::get_id(); |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
655 |
5452
8345267e8de5
Added OrthancPluginSetCurrentThreadName() in the plugin SDK
Alain Mazy <am@osimis.io>
parents:
5450
diff
changeset
|
656 boost::recursive_mutex::scoped_lock lock(threadNamesMutex_); |
8345267e8de5
Added OrthancPluginSetCurrentThreadName() in the plugin SDK
Alain Mazy <am@osimis.io>
parents:
5450
diff
changeset
|
657 |
5450
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
658 if (threadNames_.find(threadId) == threadNames_.end()) |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
659 { |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
660 // set the threadId as the thread name |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
661 SetCurrentThreadNameInternal(threadId, boost::lexical_cast<std::string>(threadId)); |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
662 } |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
663 |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
664 return threadNames_[threadId]; |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
665 } |
4006
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
666 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
667 static void GetLinePrefix(std::string& prefix, |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
668 LogLevel level, |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
669 const char* file, |
4292
6dcadbf1a8af
prefixing log messages with their category
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4275
diff
changeset
|
670 int line, |
6dcadbf1a8af
prefixing log messages with their category
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4275
diff
changeset
|
671 LogCategory category) |
4006
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
672 { |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
673 boost::filesystem::path path(file); |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
674 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
|
675 boost::posix_time::time_duration duration = now.time_of_day(); |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
676 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
677 /** |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
678 From Google Log documentation: |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
679 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
680 "Log lines have this form: |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
681 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
682 Lmmdd hh:mm:ss.uuuuuu threadid file:line] msg... |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
683 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
684 where the fields are defined as follows: |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
685 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
686 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
|
687 mm The month (zero padded; ie May is '05') |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
688 dd The day (zero padded) |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
689 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
|
690 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
|
691 file The file name |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
692 line The line number |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
693 msg The user-supplied message" |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
694 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
695 In this implementation, "threadid" is not printed. |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
696 **/ |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
697 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
698 char c; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
699 switch (level) |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
700 { |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
701 case LogLevel_ERROR: |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
702 c = 'E'; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
703 break; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
704 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
705 case LogLevel_WARNING: |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
706 c = 'W'; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
707 break; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
708 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
709 case LogLevel_INFO: |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
710 c = 'I'; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
711 break; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
712 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
713 case LogLevel_TRACE: |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
714 c = 'T'; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
715 break; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
716 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
717 default: |
4269
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
718 c = '?'; |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
719 break; |
4006
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
720 } |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
721 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
722 char date[64]; |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
723 sprintf(date, "%c%02d%02d %02d:%02d:%02d.%06d ", |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
724 c, |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
725 now.date().month().as_number(), |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
726 now.date().day().as_number(), |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
727 static_cast<int>(duration.hours()), |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
728 static_cast<int>(duration.minutes()), |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
729 static_cast<int>(duration.seconds()), |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
730 static_cast<int>(duration.fractional_seconds())); |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
731 |
5450
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
732 char threadName[20]; // thread names are limited to 16 char + a space |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
733 if (enableThreadNames_) |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
734 { |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
735 sprintf(threadName, "%16s ", GetCurrentThreadName().c_str()); |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
736 } |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
737 else |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
738 { |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
739 threadName[0] = '\0'; |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
740 } |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
741 |
9ffd6d18daf3
log lines now contain the thread name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
742 prefix = (std::string(date) + threadName + path.filename().string() + ":" + |
4006
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
743 boost::lexical_cast<std::string>(line) + "] "); |
4292
6dcadbf1a8af
prefixing log messages with their category
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4275
diff
changeset
|
744 |
4293 | 745 if (level != LogLevel_ERROR && |
746 level != LogLevel_WARNING && | |
747 category != LogCategory_GENERIC) | |
4292
6dcadbf1a8af
prefixing log messages with their category
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4275
diff
changeset
|
748 { |
6dcadbf1a8af
prefixing log messages with their category
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4275
diff
changeset
|
749 prefix += "(" + std::string(GetCategoryName(category)) + ") "; |
6dcadbf1a8af
prefixing log messages with their category
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4275
diff
changeset
|
750 } |
4006
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
751 } |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
752 |
55710d73780f
reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4005
diff
changeset
|
753 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
754 void InitializePluginContext(void* pluginContext) |
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 assert(sizeof(_OrthancPluginService) == sizeof(int32_t)); |
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 boost::mutex::scoped_lock lock(loggingStreamsMutex_); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
759 loggingStreamsContext_.reset(NULL); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
760 pluginContext_ = reinterpret_cast<OrthancPluginContext*>(pluginContext); |
5031
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
4870
diff
changeset
|
761 |
eec3e4a91663
DelayedDeletion plugin: first version
Alain Mazy <am@osimis.io>
parents:
4870
diff
changeset
|
762 EnableInfoLevel(true); // allow the plugin to log at info level (but the Orthanc Core still decides of the level) |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
763 } |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
764 |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
765 |
1489 | 766 void Initialize() |
767 { | |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
768 boost::mutex::scoped_lock lock(loggingStreamsMutex_); |
4026
05a363186da6
ORTHANC_BUILDING_FRAMEWORK_LIBRARY, Orthanc::InitializeFramework()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4017
diff
changeset
|
769 |
05a363186da6
ORTHANC_BUILDING_FRAMEWORK_LIBRARY, Orthanc::InitializeFramework()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4017
diff
changeset
|
770 if (loggingStreamsContext_.get() == NULL) |
05a363186da6
ORTHANC_BUILDING_FRAMEWORK_LIBRARY, Orthanc::InitializeFramework()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4017
diff
changeset
|
771 { |
05a363186da6
ORTHANC_BUILDING_FRAMEWORK_LIBRARY, Orthanc::InitializeFramework()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4017
diff
changeset
|
772 loggingStreamsContext_.reset(new LoggingStreamsContext); |
05a363186da6
ORTHANC_BUILDING_FRAMEWORK_LIBRARY, Orthanc::InitializeFramework()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4017
diff
changeset
|
773 } |
1489 | 774 } |
775 | |
776 void Finalize() | |
777 { | |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
778 boost::mutex::scoped_lock lock(loggingStreamsMutex_); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
779 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
|
780 } |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
781 |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
782 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
|
783 { |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
784 { |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
785 boost::mutex::scoped_lock lock(loggingStreamsMutex_); |
4317
a691916ab535
fix for 'logs are not stored in log files anymore after a /tools/reset'
Alain Mazy <alain@mazy.be>
parents:
4306
diff
changeset
|
786 loggingStreamsContext_.reset(new LoggingStreamsContext); |
a691916ab535
fix for 'logs are not stored in log files anymore after a /tools/reset'
Alain Mazy <alain@mazy.be>
parents:
4306
diff
changeset
|
787 } |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
788 |
4317
a691916ab535
fix for 'logs are not stored in log files anymore after a /tools/reset'
Alain Mazy <alain@mazy.be>
parents:
4306
diff
changeset
|
789 // Recover the old logging context if any |
a691916ab535
fix for 'logs are not stored in log files anymore after a /tools/reset'
Alain Mazy <alain@mazy.be>
parents:
4306
diff
changeset
|
790 if (!logTargetFile_.empty()) |
a691916ab535
fix for 'logs are not stored in log files anymore after a /tools/reset'
Alain Mazy <alain@mazy.be>
parents:
4306
diff
changeset
|
791 { |
a691916ab535
fix for 'logs are not stored in log files anymore after a /tools/reset'
Alain Mazy <alain@mazy.be>
parents:
4306
diff
changeset
|
792 SetTargetFile(logTargetFile_); |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
793 } |
4317
a691916ab535
fix for 'logs are not stored in log files anymore after a /tools/reset'
Alain Mazy <alain@mazy.be>
parents:
4306
diff
changeset
|
794 else if (!logTargetFolder_.empty()) |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
795 { |
4317
a691916ab535
fix for 'logs are not stored in log files anymore after a /tools/reset'
Alain Mazy <alain@mazy.be>
parents:
4306
diff
changeset
|
796 SetTargetFolder(logTargetFolder_); |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
797 } |
1489 | 798 } |
799 | |
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
|
800 |
1489 | 801 void SetTargetFolder(const std::string& path) |
802 { | |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
803 boost::mutex::scoped_lock lock(loggingStreamsMutex_); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
804 if (loggingStreamsContext_.get() != NULL) |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
805 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
806 PrepareLogFolder(loggingStreamsContext_->file_, "" /* no suffix */, path); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
807 CheckFile(loggingStreamsContext_->file_); |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
808 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
809 loggingStreamsContext_->targetFile_.clear(); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
810 loggingStreamsContext_->targetFolder_ = path; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
811 loggingStreamsContext_->warning_ = loggingStreamsContext_->file_.get(); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
812 loggingStreamsContext_->error_ = loggingStreamsContext_->file_.get(); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
813 loggingStreamsContext_->info_ = loggingStreamsContext_->file_.get(); |
4317
a691916ab535
fix for 'logs are not stored in log files anymore after a /tools/reset'
Alain Mazy <alain@mazy.be>
parents:
4306
diff
changeset
|
814 logTargetFolder_ = path; |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
815 } |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
816 } |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
817 |
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
|
818 |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
819 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
|
820 { |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
821 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
|
822 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
823 if (loggingStreamsContext_.get() != NULL) |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
824 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
825 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
|
826 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
|
827 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
828 loggingStreamsContext_->targetFile_ = path; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
829 loggingStreamsContext_->targetFolder_.clear(); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
830 loggingStreamsContext_->warning_ = loggingStreamsContext_->file_.get(); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
831 loggingStreamsContext_->error_ = loggingStreamsContext_->file_.get(); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
832 loggingStreamsContext_->info_ = loggingStreamsContext_->file_.get(); |
4317
a691916ab535
fix for 'logs are not stored in log files anymore after a /tools/reset'
Alain Mazy <alain@mazy.be>
parents:
4306
diff
changeset
|
833 logTargetFile_ = path; |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
834 } |
1489 | 835 } |
836 | |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
837 |
4273
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
838 void InternalLogger::Setup(LogCategory category, |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
839 const char* file, |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
840 int line) |
1489 | 841 { |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
842 if (pluginContext_ != NULL) |
1489 | 843 { |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
844 // We are logging using the Orthanc plugin SDK |
1489 | 845 |
4273
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
846 if (level_ == LogLevel_TRACE || |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
847 !IsCategoryEnabled(level_, category)) |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
848 { |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
849 // 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
|
850 // set to "/dev/null" |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
851 return; |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
852 } |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
853 else |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
854 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
855 pluginStream_.reset(new std::stringstream); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
856 stream_ = pluginStream_.get(); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
857 } |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
858 } |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
859 else |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
860 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
861 // We are logging in a standalone application, not inside an Orthanc plugin |
1489 | 862 |
4273
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
863 if (!IsCategoryEnabled(level_, category)) |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
864 { |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
865 // 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
|
866 // 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
|
867 return; |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
868 } |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
869 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
870 std::string prefix; |
4292
6dcadbf1a8af
prefixing log messages with their category
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4275
diff
changeset
|
871 GetLinePrefix(prefix, level_, file, line, category); |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
872 |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
873 { |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
874 // 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
|
875 // 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
|
876 lock_.lock(); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
877 |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
878 if (loggingStreamsContext_.get() == NULL) |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
879 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
880 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
|
881 lock_.unlock(); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
882 return; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
883 } |
1495
fbe40117eb21
improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1494
diff
changeset
|
884 |
4273
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
885 switch (level_) |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
886 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
887 case LogLevel_ERROR: |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
888 stream_ = loggingStreamsContext_->error_; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
889 break; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
890 |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
891 case LogLevel_WARNING: |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
892 stream_ = loggingStreamsContext_->warning_; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
893 break; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
894 |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
895 case LogLevel_INFO: |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
896 case LogLevel_TRACE: |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
897 stream_ = loggingStreamsContext_->info_; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
898 break; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
899 |
4269
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
900 default: // Should not occur |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
901 stream_ = loggingStreamsContext_->error_; |
c7bd2f21ccc3
new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4268
diff
changeset
|
902 break; |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
903 } |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
904 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
905 if (stream_ == &nullStream_) |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
906 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
907 // 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
|
908 // the global mutex. |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
909 lock_.unlock(); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
910 } |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
911 else |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
912 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
913 try |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
914 { |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
915 (*stream_) << prefix; |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
916 } |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
917 catch (...) |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
918 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
919 // 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
|
920 // memory. Fallback to a degraded mode. |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
921 stream_ = loggingStreamsContext_->error_; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
922 (*stream_) << "E???? ??:??:??.?????? ] "; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
923 } |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
924 } |
2134
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
925 } |
ddc75c6c712d
Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2015
diff
changeset
|
926 } |
1489 | 927 } |
1507 | 928 |
929 | |
4273
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
930 InternalLogger::InternalLogger(LogLevel level, |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
931 LogCategory category, |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
932 const char* file, |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
933 int line) : |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
934 lock_(loggingStreamsMutex_, boost::defer_lock_t()), |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
935 level_(level), |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
936 stream_(&nullStream_) // By default, logging to "/dev/null" is simulated |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
937 { |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
938 Setup(category, file, line); |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
939 } |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
940 |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
941 |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
942 InternalLogger::InternalLogger(LogLevel level, |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
943 const char* file, |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
944 int line) : |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
945 lock_(loggingStreamsMutex_, boost::defer_lock_t()), |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
946 level_(level), |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
947 stream_(&nullStream_) // By default, logging to "/dev/null" is simulated |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
948 { |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
949 Setup(LogCategory_GENERIC, file, line); |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
950 } |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
951 |
0034f855c023
tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4272
diff
changeset
|
952 |
1507 | 953 InternalLogger::~InternalLogger() |
954 { | |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
955 if (pluginStream_.get() != NULL) |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
956 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
957 // 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
|
958 |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
959 std::string message = pluginStream_->str(); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
960 |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
961 if (pluginContext_ != NULL) |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
962 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
963 switch (level_) |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
964 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
965 case LogLevel_ERROR: |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
966 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
|
967 break; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
968 |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
969 case LogLevel_WARNING: |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
970 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
|
971 break; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
972 |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
973 case LogLevel_INFO: |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
974 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
|
975 break; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
976 |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
977 default: |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
978 break; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
979 } |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
980 } |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
981 } |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
982 else if (stream_ != &nullStream_) |
1507 | 983 { |
984 *stream_ << "\n"; | |
985 stream_->flush(); | |
986 } | |
987 } | |
988 | |
989 | |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
990 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
|
991 { |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
992 if (pluginContext_ != NULL) |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
993 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
994 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
|
995 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
996 if (loggingStreamsContext_.get() != NULL && |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
997 loggingStreamsContext_->file_.get() != NULL) |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
998 { |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
999 loggingStreamsContext_->file_->flush(); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
1000 } |
2015
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
1001 } |
bcc575732aef
New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2014
diff
changeset
|
1002 } |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
1003 |
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
|
1004 |
4004
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
1005 void SetErrorWarnInfoLoggingStreams(std::ostream& errorStream, |
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
1006 std::ostream& warningStream, |
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
1007 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
|
1008 { |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
1009 boost::mutex::scoped_lock lock(loggingStreamsMutex_); |
4004
9b5ace33a00d
cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4003
diff
changeset
|
1010 |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
1011 loggingStreamsContext_.reset(new LoggingStreamsContext); |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
1012 loggingStreamsContext_->error_ = &errorStream; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
1013 loggingStreamsContext_->warning_ = &warningStream; |
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4010
diff
changeset
|
1014 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
|
1015 } |
1485 | 1016 } |
1017 } | |
1488 | 1018 |
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
|
1019 |
1489 | 1020 #endif // ORTHANC_ENABLE_LOGGING |