annotate OrthancFramework/Sources/Logging.cpp @ 4528:93a51d228d80

fix segmentation fault during anonymization on big-endian architectures
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 24 Feb 2021 15:07:54 +0100
parents d9473bd5ed43
children 7053502fbf97
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1485
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1731
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1485
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
4437
d9473bd5ed43 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4320
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
1485
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
8 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
10 * the License, or (at your option) any later version.
1485
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
15 * Lesser General Public License for more details.
1485
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
18 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
19 * <http://www.gnu.org/licenses/>.
1485
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "PrecompiledHeaders.h"
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "Logging.h"
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
3998
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
26 #include "OrthancException.h"
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
27
4306
548d77dfb8bc fix for vs2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4294
diff changeset
28 #include <stdint.h>
548d77dfb8bc fix for vs2008
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4294
diff changeset
29
3998
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
30
4269
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
31 /*********************************************************
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
32 * Common section
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
33 *********************************************************/
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
34
3998
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
35 namespace Orthanc
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
36 {
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
37 namespace Logging
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
38 {
4270
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
39 static const uint32_t ALL_CATEGORIES_MASK = 0xffffffff;
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
40
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
41 static uint32_t infoCategoriesMask_ = 0;
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
42 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
43 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
44 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
45
3998
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
46 const char* EnumerationToString(LogLevel level)
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
47 {
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
48 switch (level)
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
49 {
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
50 case LogLevel_ERROR:
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
51 return "ERROR";
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
52
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
53 case LogLevel_WARNING:
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
54 return "WARNING";
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
55
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
56 case LogLevel_INFO:
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
57 return "INFO";
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
58
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
59 case LogLevel_TRACE:
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
60 return "TRACE";
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
61
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
62 default:
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
63 throw OrthancException(ErrorCode_ParameterOutOfRange);
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
64 }
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
65 }
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
66
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 LogLevel StringToLogLevel(const char *level)
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
69 {
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
70 if (strcmp(level, "ERROR") == 0)
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
71 {
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
72 return LogLevel_ERROR;
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
73 }
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
74 else if (strcmp(level, "WARNING") == 0)
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
75 {
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
76 return LogLevel_WARNING;
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
77 }
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
78 else if (strcmp(level, "INFO") == 0)
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
79 {
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
80 return LogLevel_INFO;
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
81 }
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
82 else if (strcmp(level, "TRACE") == 0)
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
83 {
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
84 return LogLevel_TRACE;
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
85 }
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
86 else
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
87 {
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
88 throw OrthancException(ErrorCode_InternalError);
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
89 }
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
90 }
4269
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
91
4270
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
92
4269
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
93 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
94 {
4270
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
95 if (enabled)
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
96 {
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
97 infoCategoriesMask_ = ALL_CATEGORIES_MASK;
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
98 }
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
99 else
4269
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
100 {
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
101 // 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
102 infoCategoriesMask_ = 0;
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
103 traceCategoriesMask_ = 0;
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
104 }
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 bool IsInfoLevelEnabled()
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
109 {
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
110 return (infoCategoriesMask_ != 0);
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
111 }
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 void EnableTraceLevel(bool enabled)
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
115 {
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
116 if (enabled)
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
117 {
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
118 // Also enable the "INFO" level when trace-level debugging is enabled
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
119 infoCategoriesMask_ = ALL_CATEGORIES_MASK;
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
120 traceCategoriesMask_ = ALL_CATEGORIES_MASK;
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
121 }
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
122 else
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
123 {
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
124 traceCategoriesMask_ = 0;
4269
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
125 }
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
4270
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
128
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
129 bool IsTraceLevelEnabled()
4269
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
130 {
4270
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
131 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
132 }
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
133
4270
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
134
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
135 void SetCategoryEnabled(LogLevel level,
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
136 LogCategory category,
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
137 bool enabled)
4269
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
138 {
4271
1bd14c900699 LogCategory_PLUGINS
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4270
diff changeset
139 // 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
140 // for "verbose" (in other words, trace level implies verbose level)
1bd14c900699 LogCategory_PLUGINS
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4270
diff changeset
141 assert((traceCategoriesMask_ & infoCategoriesMask_) == traceCategoriesMask_);
1bd14c900699 LogCategory_PLUGINS
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4270
diff changeset
142
4270
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
143 if (level == LogLevel_INFO)
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
144 {
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
145 if (enabled)
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
146 {
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
147 infoCategoriesMask_ |= static_cast<uint32_t>(category);
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
148 }
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
149 else
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
150 {
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
151 infoCategoriesMask_ &= ~static_cast<uint32_t>(category);
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
152 traceCategoriesMask_ &= ~static_cast<uint32_t>(category);
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
153 }
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 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
156 {
4270
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
157 if (enabled)
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
158 {
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
159 traceCategoriesMask_ |= static_cast<uint32_t>(category);
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
160 infoCategoriesMask_ |= static_cast<uint32_t>(category);
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
161 }
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
162 else
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
163 {
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
164 traceCategoriesMask_ &= ~static_cast<uint32_t>(category);
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
165 }
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 else
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
168 {
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
169 throw OrthancException(ErrorCode_ParameterOutOfRange,
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
170 "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
171 }
4271
1bd14c900699 LogCategory_PLUGINS
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4270
diff changeset
172
1bd14c900699 LogCategory_PLUGINS
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4270
diff changeset
173 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
174 }
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
175
4270
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
176
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
177 bool IsCategoryEnabled(LogLevel level,
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
178 LogCategory category)
4269
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
179 {
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
180 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
181 level == LogLevel_WARNING)
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
182 {
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
183 return true;
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
184 }
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
185 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
186 {
4270
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
187 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
188 }
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
189 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
190 {
4270
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
191 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
192 }
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
193 else
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
194 {
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
195 return false;
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
196 }
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
197 }
4270
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
198
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
199
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
200 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
201 const std::string& category)
4270
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
202 {
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
203 if (category == "generic")
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
204 {
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
205 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
206 return true;
4270
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
207 }
4271
1bd14c900699 LogCategory_PLUGINS
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4270
diff changeset
208 else if (category == "plugins")
1bd14c900699 LogCategory_PLUGINS
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4270
diff changeset
209 {
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
210 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
211 return true;
4271
1bd14c900699 LogCategory_PLUGINS
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4270
diff changeset
212 }
4294
0923247e69f6 log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents: 4293
diff changeset
213 else if (category == "http")
4272
1661544ea94d LogCategory_REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4271
diff changeset
214 {
4294
0923247e69f6 log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents: 4293
diff changeset
215 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
216 return true;
4272
1661544ea94d LogCategory_REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4271
diff changeset
217 }
4270
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
218 else if (category == "dicom")
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
219 {
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
220 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
221 return true;
4270
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
222 }
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
223 else if (category == "sqlite")
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
224 {
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
225 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
226 return true;
4270
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
227 }
4294
0923247e69f6 log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents: 4293
diff changeset
228 else if (category == "jobs")
0923247e69f6 log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents: 4293
diff changeset
229 {
0923247e69f6 log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents: 4293
diff changeset
230 target = LogCategory_JOBS;
0923247e69f6 log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents: 4293
diff changeset
231 return true;
0923247e69f6 log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents: 4293
diff changeset
232 }
0923247e69f6 log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents: 4293
diff changeset
233 else if (category == "lua")
0923247e69f6 log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents: 4293
diff changeset
234 {
0923247e69f6 log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents: 4293
diff changeset
235 target = LogCategory_LUA;
0923247e69f6 log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents: 4293
diff changeset
236 return true;
0923247e69f6 log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents: 4293
diff changeset
237 }
4270
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
238 else
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
239 {
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
240 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
241 }
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
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
245 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
246 {
4294
0923247e69f6 log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents: 4293
diff changeset
247 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
248 }
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
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
251 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
252 {
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
253 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
254 {
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 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
256 }
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 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
258 {
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
259 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
260 }
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 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
265 {
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 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
267 {
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 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
269 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
270
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 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
272 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
273
4294
0923247e69f6 log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents: 4293
diff changeset
274 case LogCategory_HTTP:
0923247e69f6 log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents: 4293
diff changeset
275 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
276
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 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
278 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
279
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 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
281 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
282
4294
0923247e69f6 log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents: 4293
diff changeset
283 case LogCategory_JOBS:
0923247e69f6 log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents: 4293
diff changeset
284 return "jobs";
0923247e69f6 log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents: 4293
diff changeset
285
0923247e69f6 log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents: 4293
diff changeset
286 case LogCategory_LUA:
0923247e69f6 log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents: 4293
diff changeset
287 return "lua";
0923247e69f6 log categories: rest -> http + added lua & jobs
Alain Mazy <alain@mazy.be>
parents: 4293
diff changeset
288
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
289 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
290 throw OrthancException(ErrorCode_ParameterOutOfRange);
4270
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
291 }
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
292 }
3998
b3f09bc9734b sharing more code between the loggers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3996
diff changeset
293 }
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
4269
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
297
1551
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
298 #if ORTHANC_ENABLE_LOGGING != 1
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
299
4269
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
300 /*********************************************************
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
301 * 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
302 *********************************************************/
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
303
1551
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
304 namespace Orthanc
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
305 {
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
306 namespace Logging
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
307 {
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
308 void InitializePluginContext(void* pluginContext)
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
309 {
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
1551
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
312 void Initialize()
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
313 {
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 void Finalize()
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
317 {
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
318 }
1485
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
320 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
321 {
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 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
325 {
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 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
329 {
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
1551
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
332 void SetTargetFolder(const std::string& path)
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
333 {
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
2243
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
338
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
339 #elif ORTHANC_ENABLE_LOGGING_STDIO == 1
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
340
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
341 /*********************************************************
3359
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
342 * 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
343 * 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
344 * definition of __EMSCRIPTEN__)
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
345 *********************************************************/
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 #include <stdio.h>
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
348
3359
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
349 #ifdef __EMSCRIPTEN__
3506
d2b9981017c4 better handling of HTTP security
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3505
diff changeset
350 # 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
351 #endif
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
352
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
353 namespace Orthanc
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
354 {
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
355 namespace Logging
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
356 {
3359
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
357 #ifdef __EMSCRIPTEN__
4010
f0ee3f1db775 removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4006
diff changeset
358 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
359 {
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
360 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
361 }
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
362
4010
f0ee3f1db775 removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4006
diff changeset
363 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
364 {
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
365 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
366 }
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
367
4010
f0ee3f1db775 removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4006
diff changeset
368 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
369 {
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
370 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
371 }
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
372
4010
f0ee3f1db775 removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4006
diff changeset
373 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
374 {
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
375 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
376 }
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
377 #else /* __EMSCRIPTEN__ not #defined */
4010
f0ee3f1db775 removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4006
diff changeset
378 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
379 {
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
380 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
381 }
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
382
4010
f0ee3f1db775 removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4006
diff changeset
383 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
384 {
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
385 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
386 }
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
387
4010
f0ee3f1db775 removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4006
diff changeset
388 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
389 {
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
390 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
391 }
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
392
4010
f0ee3f1db775 removed unused Logging::SetErrorWarnInfoTraceLoggingFunctions()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4006
diff changeset
393 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
394 {
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
395 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
396 }
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
397 #endif /* __EMSCRIPTEN__ */
3359
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
398
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
399
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
400 InternalLogger::~InternalLogger()
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
401 {
3489
e7723a39adf8 Fixed alignment issue in Toolbox::DetectEndianness() + made the internal logger
Benjamin Golinvaux <bgo@osimis.io>
parents: 3477
diff changeset
402 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
403
4270
251a8b07fa37 logging categories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4269
diff changeset
404 if (IsCategoryEnabled(level_, category_))
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
405 {
4269
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
406 switch (level_)
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
407 {
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
408 case LogLevel_ERROR:
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
409 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
410 break;
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
411
4269
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
412 case LogLevel_WARNING:
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
413 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
414 break;
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
415
4269
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
416 case LogLevel_INFO:
4017
c783f4f29390 log using emscripten
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4014
diff changeset
417 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
418 // 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
419 break;
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
420
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
421 case LogLevel_TRACE:
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
422 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
423 break;
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
424
4269
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
425 default:
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
426 {
4269
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
427 std::stringstream ss;
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
428 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
429 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
430 ErrorLogFunc(s.c_str());
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
431 }
3359
815b81142ff7 Enable custom logging functions to redirect to emscripten specific logging calls
Benjamin Golinvaux <bgo@osimis.io>
parents: 3353
diff changeset
432 }
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
433 }
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
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
436 void InitializePluginContext(void* pluginContext)
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
437 {
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
3358
849c651c1381 fix missing symbol
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
440 void Initialize()
849c651c1381 fix missing symbol
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
441 {
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
3995
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
444 void Finalize()
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
445 {
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 void Reset()
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
449 {
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 void Flush()
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
453 {
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 void SetTargetFile(const std::string& path)
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
457 {
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 void SetTargetFolder(const std::string& path)
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
461 {
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
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
467 #else
3995
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
468
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
469 /*********************************************************
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
470 * 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
471 * mimics behavior from Google Log.
3995
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
472 *********************************************************/
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 #include <cassert>
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
475
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
476 namespace
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 /**
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
479 * This is minimal implementation of the context for an Orthanc
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
480 * plugin, limited to the logging facilities, and that is binary
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
481 * compatible with the definitions of "OrthancCPlugin.h"
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
482 **/
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
483 typedef enum
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 _OrthancPluginService_LogInfo = 1,
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
486 _OrthancPluginService_LogWarning = 2,
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
487 _OrthancPluginService_LogError = 3,
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
488 _OrthancPluginService_INTERNAL = 0x7fffffff
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
489 } _OrthancPluginService;
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
490
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
491 typedef struct _OrthancPluginContext_t
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 void* pluginsManager;
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
494 const char* orthancVersion;
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
495 void (*Free) (void* buffer);
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
496 int32_t (*InvokeService) (struct _OrthancPluginContext_t* context,
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
497 _OrthancPluginService service,
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
498 const void* params);
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
499 } OrthancPluginContext;
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
500 }
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
501
1f405a3fdeca reorganizing Logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3712
diff changeset
502
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
503 #include "Enumerations.h"
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
504 #include "SystemToolbox.h"
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
505
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
506 #include <fstream>
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
507 #include <boost/filesystem.hpp>
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
508 #include <boost/thread.hpp>
2367
2aff870c2c58 refactoring of BoostConfiguration.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2253
diff changeset
509 #include <boost/date_time/posix_time/posix_time.hpp>
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
510
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
511
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
512 namespace
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
513 {
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
514 struct LoggingStreamsContext
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
515 {
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
516 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
517 std::string targetFolder_;
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
518
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
519 std::ostream* error_;
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
520 std::ostream* warning_;
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
521 std::ostream* info_;
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
522
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
523 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
524
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
525 LoggingStreamsContext() :
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
526 error_(&std::cerr),
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
527 warning_(&std::cerr),
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
528 info_(&std::cerr)
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
529 {
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
530 }
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
531 };
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
532 }
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
533
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
534
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
535
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
536 static std::unique_ptr<LoggingStreamsContext> loggingStreamsContext_;
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
537 static boost::mutex loggingStreamsMutex_;
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
538 static Orthanc::Logging::NullStream nullStream_;
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
539 static OrthancPluginContext* pluginContext_ = NULL;
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
540
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
541
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
542 namespace Orthanc
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
543 {
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
544 namespace Logging
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
545 {
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
546 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
547 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
548 const std::string& suffix,
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
549 const std::string& directory)
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
550 {
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
551 /**
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
552 From Google Log documentation:
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
553
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
554 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
555 "<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
556 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
557 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
558
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
559 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
560 **/
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 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
563 boost::filesystem::path root(directory);
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2134
diff changeset
564 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
565
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
566 if (!boost::filesystem::exists(root) ||
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
567 !boost::filesystem::is_directory(root))
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
568 {
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
569 throw OrthancException(ErrorCode_CannotWriteFile);
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
570 }
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 char date[64];
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
573 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
574 static_cast<int>(now.date().year()),
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
575 now.date().month().as_number(),
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
576 now.date().day().as_number(),
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
577 static_cast<int>(now.time_of_day().hours()),
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
578 static_cast<int>(now.time_of_day().minutes()),
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
579 static_cast<int>(now.time_of_day().seconds()),
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2134
diff changeset
580 SystemToolbox::GetProcessId());
1490
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 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
583
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
584 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
585 link = (root / (programName + ".log" + suffix));
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
586 }
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
587
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
588
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
589 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
590 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
591 const std::string& directory)
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 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
594 GetLogPath(log, link, suffix, directory);
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
595
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
596 #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
597 boost::filesystem::remove(link);
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
598 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
599 #endif
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
600
1494
a13581480b1f fix mingw build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1490
diff changeset
601 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
602 }
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
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
605 // "loggingStreamsMutex_" must be locked
4006
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
606 static void CheckFile(std::unique_ptr<std::ofstream>& f)
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
607 {
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
608 if (loggingStreamsContext_->file_.get() == NULL ||
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
609 !loggingStreamsContext_->file_->is_open())
4006
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
610 {
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
611 throw OrthancException(ErrorCode_CannotWriteFile);
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
612 }
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
613 }
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
614
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
615
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
616 static void GetLinePrefix(std::string& prefix,
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
617 LogLevel level,
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
618 const char* file,
4292
6dcadbf1a8af prefixing log messages with their category
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4275
diff changeset
619 int line,
6dcadbf1a8af prefixing log messages with their category
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4275
diff changeset
620 LogCategory category)
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 boost::filesystem::path path(file);
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
623 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
624 boost::posix_time::time_duration duration = now.time_of_day();
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
625
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
626 /**
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
627 From Google Log documentation:
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
628
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
629 "Log lines have this form:
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
630
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
631 Lmmdd hh:mm:ss.uuuuuu threadid file:line] msg...
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
632
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
633 where the fields are defined as follows:
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
634
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
635 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
636 mm The month (zero padded; ie May is '05')
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
637 dd The day (zero padded)
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
638 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
639 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
640 file The file name
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
641 line The line number
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
642 msg The user-supplied message"
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
643
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
644 In this implementation, "threadid" is not printed.
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
645 **/
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
646
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
647 char c;
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
648 switch (level)
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
649 {
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
650 case LogLevel_ERROR:
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
651 c = 'E';
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
652 break;
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
653
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
654 case LogLevel_WARNING:
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
655 c = 'W';
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
656 break;
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
657
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
658 case LogLevel_INFO:
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
659 c = 'I';
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
660 break;
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
661
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
662 case LogLevel_TRACE:
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
663 c = 'T';
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
664 break;
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
665
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
666 default:
4269
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
667 c = '?';
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
668 break;
4006
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
669 }
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
670
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
671 char date[64];
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
672 sprintf(date, "%c%02d%02d %02d:%02d:%02d.%06d ",
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
673 c,
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
674 now.date().month().as_number(),
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
675 now.date().day().as_number(),
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
676 static_cast<int>(duration.hours()),
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
677 static_cast<int>(duration.minutes()),
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
678 static_cast<int>(duration.seconds()),
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
679 static_cast<int>(duration.fractional_seconds()));
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
680
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
681 prefix = (std::string(date) + path.filename().string() + ":" +
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
682 boost::lexical_cast<std::string>(line) + "] ");
4292
6dcadbf1a8af prefixing log messages with their category
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4275
diff changeset
683
4293
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4292
diff changeset
684 if (level != LogLevel_ERROR &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4292
diff changeset
685 level != LogLevel_WARNING &&
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4292
diff changeset
686 category != LogCategory_GENERIC)
4292
6dcadbf1a8af prefixing log messages with their category
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4275
diff changeset
687 {
6dcadbf1a8af prefixing log messages with their category
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4275
diff changeset
688 prefix += "(" + std::string(GetCategoryName(category)) + ") ";
6dcadbf1a8af prefixing log messages with their category
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4275
diff changeset
689 }
4006
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
690 }
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
691
55710d73780f reorganizing Logging.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4005
diff changeset
692
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
693 void InitializePluginContext(void* pluginContext)
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
694 {
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
695 assert(sizeof(_OrthancPluginService) == sizeof(int32_t));
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
696
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
697 boost::mutex::scoped_lock lock(loggingStreamsMutex_);
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
698 loggingStreamsContext_.reset(NULL);
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
699 pluginContext_ = reinterpret_cast<OrthancPluginContext*>(pluginContext);
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
700 }
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
701
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
702
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
703 void Initialize()
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
704 {
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
705 boost::mutex::scoped_lock lock(loggingStreamsMutex_);
4026
05a363186da6 ORTHANC_BUILDING_FRAMEWORK_LIBRARY, Orthanc::InitializeFramework()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4017
diff changeset
706
05a363186da6 ORTHANC_BUILDING_FRAMEWORK_LIBRARY, Orthanc::InitializeFramework()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4017
diff changeset
707 if (loggingStreamsContext_.get() == NULL)
05a363186da6 ORTHANC_BUILDING_FRAMEWORK_LIBRARY, Orthanc::InitializeFramework()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4017
diff changeset
708 {
05a363186da6 ORTHANC_BUILDING_FRAMEWORK_LIBRARY, Orthanc::InitializeFramework()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4017
diff changeset
709 loggingStreamsContext_.reset(new LoggingStreamsContext);
05a363186da6 ORTHANC_BUILDING_FRAMEWORK_LIBRARY, Orthanc::InitializeFramework()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4017
diff changeset
710 }
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
711 }
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
712
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
713 void Finalize()
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
714 {
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
715 boost::mutex::scoped_lock lock(loggingStreamsMutex_);
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
716 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
717 }
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
718
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
719 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
720 {
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
721 {
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
722 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
723 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
724 }
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
725
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
726 // 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
727 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
728 {
a691916ab535 fix for 'logs are not stored in log files anymore after a /tools/reset'
Alain Mazy <alain@mazy.be>
parents: 4306
diff changeset
729 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
730 }
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
731 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
732 {
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
733 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
734 }
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
735 }
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
736
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
737
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
738 void SetTargetFolder(const std::string& path)
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
739 {
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
740 boost::mutex::scoped_lock lock(loggingStreamsMutex_);
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
741 if (loggingStreamsContext_.get() != NULL)
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
742 {
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
743 PrepareLogFolder(loggingStreamsContext_->file_, "" /* no suffix */, path);
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
744 CheckFile(loggingStreamsContext_->file_);
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
745
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
746 loggingStreamsContext_->targetFile_.clear();
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
747 loggingStreamsContext_->targetFolder_ = path;
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
748 loggingStreamsContext_->warning_ = loggingStreamsContext_->file_.get();
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
749 loggingStreamsContext_->error_ = loggingStreamsContext_->file_.get();
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
750 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
751 logTargetFolder_ = path;
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
752 }
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
753 }
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
754
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
755
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
756 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
757 {
4014
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_);
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
759
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
760 if (loggingStreamsContext_.get() != NULL)
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
761 {
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
762 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
763 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
764
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
765 loggingStreamsContext_->targetFile_ = path;
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
766 loggingStreamsContext_->targetFolder_.clear();
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
767 loggingStreamsContext_->warning_ = loggingStreamsContext_->file_.get();
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
768 loggingStreamsContext_->error_ = loggingStreamsContext_->file_.get();
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
769 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
770 logTargetFile_ = path;
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
771 }
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
772 }
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
773
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
774
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
775 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
776 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
777 int line)
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
778 {
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
779 if (pluginContext_ != NULL)
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
780 {
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
781 // We are logging using the Orthanc plugin SDK
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
782
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
783 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
784 !IsCategoryEnabled(level_, category))
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
785 {
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
786 // 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
787 // set to "/dev/null"
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
788 return;
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
789 }
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
790 else
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
791 {
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
792 pluginStream_.reset(new std::stringstream);
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
793 stream_ = pluginStream_.get();
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
794 }
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
795 }
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
796 else
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
797 {
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
798 // We are logging in a standalone application, not inside an Orthanc plugin
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
799
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
800 if (!IsCategoryEnabled(level_, category))
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
801 {
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
802 // 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
803 // 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
804 return;
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
805 }
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
806
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
807 std::string prefix;
4292
6dcadbf1a8af prefixing log messages with their category
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4275
diff changeset
808 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
809
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
810 {
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
811 // 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
812 // 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
813 lock_.lock();
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
814
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
815 if (loggingStreamsContext_.get() == NULL)
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
816 {
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
817 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
818 lock_.unlock();
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
819 return;
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
820 }
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
821
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
822 switch (level_)
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
823 {
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
824 case LogLevel_ERROR:
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
825 stream_ = loggingStreamsContext_->error_;
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
826 break;
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
827
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
828 case LogLevel_WARNING:
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
829 stream_ = loggingStreamsContext_->warning_;
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
830 break;
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
831
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
832 case LogLevel_INFO:
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
833 case LogLevel_TRACE:
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
834 stream_ = loggingStreamsContext_->info_;
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
835 break;
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
836
4269
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
837 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
838 stream_ = loggingStreamsContext_->error_;
c7bd2f21ccc3 new macro CLOG, and sharing more code between logging engines
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4268
diff changeset
839 break;
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
840 }
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
841
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
842 if (stream_ == &nullStream_)
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
843 {
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
844 // 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
845 // the global mutex.
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
846 lock_.unlock();
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
847 }
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
848 else
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
849 {
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
850 try
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
851 {
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
852 (*stream_) << prefix;
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
853 }
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
854 catch (...)
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
855 {
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
856 // 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
857 // memory. Fallback to a degraded mode.
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
858 stream_ = loggingStreamsContext_->error_;
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
859 (*stream_) << "E???? ??:??:??.?????? ] ";
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 }
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
862 }
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
863 }
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
864 }
1507
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
865
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
866
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
867 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
868 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
869 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
870 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
871 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
872 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
873 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
874 {
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
875 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
876 }
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
877
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
878
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
879 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
880 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
881 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
882 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
883 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
884 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
885 {
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
886 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
887 }
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
888
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
889
1507
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
890 InternalLogger::~InternalLogger()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
891 {
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
892 if (pluginStream_.get() != NULL)
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
893 {
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
894 // 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
895
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
896 std::string message = pluginStream_->str();
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
897
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
898 if (pluginContext_ != NULL)
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
899 {
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
900 switch (level_)
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
901 {
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
902 case LogLevel_ERROR:
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
903 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
904 break;
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
905
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
906 case LogLevel_WARNING:
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
907 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
908 break;
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
909
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
910 case LogLevel_INFO:
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
911 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
912 break;
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
913
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
914 default:
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
915 break;
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
916 }
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
917 }
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 else if (stream_ != &nullStream_)
1507
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
920 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
921 *stream_ << "\n";
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
922 stream_->flush();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
923 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
924 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
925
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
926
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
927 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
928 {
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
929 if (pluginContext_ != NULL)
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
930 {
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
931 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
932
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
933 if (loggingStreamsContext_.get() != NULL &&
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
934 loggingStreamsContext_->file_.get() != NULL)
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
935 {
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
936 loggingStreamsContext_->file_->flush();
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
937 }
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
938 }
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
939 }
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
940
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
941
4004
9b5ace33a00d cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4003
diff changeset
942 void SetErrorWarnInfoLoggingStreams(std::ostream& errorStream,
9b5ace33a00d cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4003
diff changeset
943 std::ostream& warningStream,
9b5ace33a00d cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4003
diff changeset
944 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
945 {
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
946 boost::mutex::scoped_lock lock(loggingStreamsMutex_);
4004
9b5ace33a00d cleaning SetErrorWarnInfoLoggingStreams()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4003
diff changeset
947
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
948 loggingStreamsContext_.reset(new LoggingStreamsContext);
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
949 loggingStreamsContext_->error_ = &errorStream;
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
950 loggingStreamsContext_->warning_ = &warningStream;
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4010
diff changeset
951 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
952 }
1485
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
953 }
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
954 }
1488
c8763b603b0e flag for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1487
diff changeset
955
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
956
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
957 #endif // ORTHANC_ENABLE_LOGGING