annotate Core/Logging.cpp @ 3995:1f405a3fdeca

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