annotate OrthancFramework/Sources/Logging.cpp @ 4269:c7bd2f21ccc3

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