annotate Core/Logging.cpp @ 3358:849c651c1381

fix missing symbol
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 02 May 2019 13:23:29 +0200
parents 4e43e67f8ecf
children ea07b29c6d0e
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
3060
4e43e67f8ecf preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2836
diff changeset
5 * Copyright (C) 2017-2019 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 }
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
66
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
67 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
68 {
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
69 }
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
70
1551
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
71 void SetTargetFolder(const std::string& path)
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
72 {
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
73 }
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
74 }
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
75 }
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
76
2243
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
77
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
78 #elif ORTHANC_ENABLE_LOGGING_PLUGIN == 1
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
79
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
80 /*********************************************************
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
81 * Logger compatible with the Orthanc plugin SDK
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
82 *********************************************************/
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
83
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
84 #include <boost/lexical_cast.hpp>
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
85
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
86 namespace Orthanc
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
87 {
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
88 namespace Logging
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
89 {
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
90 static OrthancPluginContext* context_ = NULL;
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
91
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
92 void Initialize(OrthancPluginContext* context)
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
93 {
2253
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
94 context_ = context;
2243
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
95 }
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
96
2505
a4f885670da7 fix Windows build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2498
diff changeset
97 InternalLogger::InternalLogger(InternalLevel level,
2243
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
98 const char* file /* ignored */,
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
99 int line /* ignored */) :
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
100 level_(level)
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
101 {
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
102 }
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
103
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
104 InternalLogger::~InternalLogger()
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
105 {
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
106 if (context_ != NULL)
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
107 {
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
108 switch (level_)
2243
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
109 {
2505
a4f885670da7 fix Windows build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2498
diff changeset
110 case InternalLevel_ERROR:
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
111 OrthancPluginLogError(context_, message_.c_str());
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
112 break;
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
113
2505
a4f885670da7 fix Windows build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2498
diff changeset
114 case InternalLevel_WARNING:
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
115 OrthancPluginLogWarning(context_, message_.c_str());
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
116 break;
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
117
2505
a4f885670da7 fix Windows build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2498
diff changeset
118 case InternalLevel_INFO:
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
119 OrthancPluginLogInfo(context_, message_.c_str());
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
120 break;
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
121
2505
a4f885670da7 fix Windows build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2498
diff changeset
122 case InternalLevel_TRACE:
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
123 // Not used by plugins
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
124 break;
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
125
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
126 default:
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
127 {
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
128 std::string s = ("Unknown log level (" + boost::lexical_cast<std::string>(level_) +
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
129 ") for message: " + message_);
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
130 OrthancPluginLogError(context_, s.c_str());
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
131 break;
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
132 }
2253
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2244
diff changeset
133 }
2243
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
134 }
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
135 }
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
136 }
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
137 }
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
138
2dbfdafc2512 Logger compatible with the Orthanc plugin SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2143
diff changeset
139
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
140 #elif ORTHANC_ENABLE_LOGGING_STDIO == 1
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
141
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
142 /*********************************************************
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
143 * Logger compatible with <stdio.h>
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
144 *********************************************************/
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
145
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
146 #include <stdio.h>
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
147 #include <boost/lexical_cast.hpp>
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
148
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
149 namespace Orthanc
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
150 {
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
151 namespace Logging
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
152 {
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
153 static bool globalVerbose_ = false;
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
154 static bool globalTrace_ = false;
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
155
2505
a4f885670da7 fix Windows build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2498
diff changeset
156 InternalLogger::InternalLogger(InternalLevel level,
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
157 const char* file /* ignored */,
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
158 int line /* ignored */) :
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
159 level_(level)
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
160 {
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
161 }
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
162
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
163 InternalLogger::~InternalLogger()
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
164 {
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
165 switch (level_)
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
166 {
2505
a4f885670da7 fix Windows build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2498
diff changeset
167 case InternalLevel_ERROR:
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
168 fprintf(stderr, "E: %s\n", message_.c_str());
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
169 break;
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
170
2505
a4f885670da7 fix Windows build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2498
diff changeset
171 case InternalLevel_WARNING:
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
172 fprintf(stdout, "W: %s\n", message_.c_str());
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
173 break;
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
174
2505
a4f885670da7 fix Windows build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2498
diff changeset
175 case InternalLevel_INFO:
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
176 if (globalVerbose_)
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
177 {
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
178 fprintf(stdout, "I: %s\n", message_.c_str());
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
179 }
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
180 break;
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
181
2505
a4f885670da7 fix Windows build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2498
diff changeset
182 case InternalLevel_TRACE:
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
183 if (globalTrace_)
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
184 {
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
185 fprintf(stdout, "T: %s\n", message_.c_str());
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
186 }
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
187 break;
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
188
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
189 default:
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
190 fprintf(stderr, "Unknown log level (%d) for message: %s\n", level_, message_.c_str());
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
191 }
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
192 }
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
193
3358
849c651c1381 fix missing symbol
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
194 void Initialize()
849c651c1381 fix missing symbol
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
195 {
849c651c1381 fix missing symbol
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
196 }
849c651c1381 fix missing symbol
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
197
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
198 void EnableInfoLevel(bool enabled)
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
199 {
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
200 globalVerbose_ = enabled;
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
201 }
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
202
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
203 void EnableTraceLevel(bool enabled)
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
204 {
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
205 globalTrace_ = enabled;
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
206 }
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
207 }
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
208 }
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
209
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
210
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
211 #else /* ORTHANC_ENABLE_LOGGING_PLUGIN == 0 &&
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
212 ORTHANC_ENABLE_LOGGING_STDIO == 0 &&
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
213 ORTHANC_ENABLE_LOGGING == 1 */
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
214
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
215 /*********************************************************
2014
e39a2657f1c6 Dropped support of Google Log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
216 * Internal logger of Orthanc, that mimics some
e39a2657f1c6 Dropped support of Google Log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
217 * behavior from Google Log.
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
218 *********************************************************/
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
219
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
220 #include "OrthancException.h"
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
221 #include "Enumerations.h"
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
222 #include "Toolbox.h"
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
223
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
224 #if ORTHANC_SANDBOXED == 1
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
225 # include <stdio.h>
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
226 #else
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
227 # include "SystemToolbox.h"
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
228 #endif
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
229
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
230 #include <fstream>
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
231 #include <boost/filesystem.hpp>
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
232 #include <boost/thread.hpp>
2367
2aff870c2c58 refactoring of BoostConfiguration.cmake
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2253
diff changeset
233 #include <boost/date_time/posix_time/posix_time.hpp>
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
234
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
235
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
236 namespace
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
237 {
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
238 struct LoggingContext
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
239 {
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
240 bool infoEnabled_;
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
241 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
242 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
243 std::string targetFolder_;
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
244
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
245 std::ostream* error_;
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
246 std::ostream* warning_;
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
247 std::ostream* info_;
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
248
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
249 std::auto_ptr<std::ofstream> file_;
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
250
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
251 LoggingContext() :
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
252 infoEnabled_(false),
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
253 traceEnabled_(false),
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
254 error_(&std::cerr),
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
255 warning_(&std::cerr),
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
256 info_(&std::cerr)
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
257 {
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
258 }
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
259 };
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
260 }
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
261
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
262
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
263
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
264 static std::auto_ptr<LoggingContext> loggingContext_;
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
265 static boost::mutex loggingMutex_;
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
266
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
267
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
268
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
269 namespace Orthanc
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
270 {
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
271 namespace Logging
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
272 {
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
273 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
274 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
275 const std::string& suffix,
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
276 const std::string& directory)
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
277 {
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
278 /**
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
279 From Google Log documentation:
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
280
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
281 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
282 "<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
283 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
284 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
285
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
286 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
287 **/
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
288
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
289 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
290 boost::filesystem::path root(directory);
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2134
diff changeset
291 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
292
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
293 if (!boost::filesystem::exists(root) ||
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
294 !boost::filesystem::is_directory(root))
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
295 {
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
296 throw OrthancException(ErrorCode_CannotWriteFile);
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
297 }
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
298
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
299 char date[64];
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
300 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
301 static_cast<int>(now.date().year()),
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
302 now.date().month().as_number(),
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
303 now.date().day().as_number(),
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
304 static_cast<int>(now.time_of_day().hours()),
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
305 static_cast<int>(now.time_of_day().minutes()),
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
306 static_cast<int>(now.time_of_day().seconds()),
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2134
diff changeset
307 SystemToolbox::GetProcessId());
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
308
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
309 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
310
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
311 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
312 link = (root / (programName + ".log" + suffix));
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
313 }
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
314
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
315
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
316 static void PrepareLogFolder(std::auto_ptr<std::ofstream>& file,
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
317 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
318 const std::string& directory)
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
319 {
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
320 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
321 GetLogPath(log, link, suffix, directory);
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
322
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
323 #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
324 boost::filesystem::remove(link);
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
325 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
326 #endif
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
327
1494
a13581480b1f fix mingw build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1490
diff changeset
328 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
329 }
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
330
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
331
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
332 void Initialize()
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
333 {
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
334 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
335 loggingContext_.reset(new LoggingContext);
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
336 }
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
337
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
338 void Finalize()
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
339 {
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
340 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
341 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
342 }
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
343
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
344 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
345 {
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
346 // Recover the old 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
347 std::auto_ptr<LoggingContext> old;
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
348
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
349 {
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
350 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
351 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
352 {
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
353 return;
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
354 }
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
355 else
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
356 {
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
357 old = loggingContext_;
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
358
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
359 // 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
360 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
361 }
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
362 }
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
363
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
364 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
365 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
366
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
367 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
368 {
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
369 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
370 }
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
371 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
372 {
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
373 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
374 }
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
375 }
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
376
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
377 void EnableInfoLevel(bool enabled)
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
378 {
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
379 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
380 assert(loggingContext_.get() != NULL);
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
381
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
382 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
383
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
384 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
385 {
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
386 // 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
387 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
388 }
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
389 }
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
390
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
391 void EnableTraceLevel(bool enabled)
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
392 {
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
393 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
394 assert(loggingContext_.get() != NULL);
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
395
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
396 loggingContext_->traceEnabled_ = enabled;
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
397
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
398 if (enabled)
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
399 {
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
400 // 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
401 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
402 }
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
403 }
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
404
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
405
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
406 static void CheckFile(std::auto_ptr<std::ofstream>& f)
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
407 {
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
408 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
409 !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
410 {
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
411 throw OrthancException(ErrorCode_CannotWriteFile);
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
412 }
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
413 }
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
414
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
415 void SetTargetFolder(const std::string& path)
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
416 {
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
417 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
418 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
419
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
420 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
421 CheckFile(loggingContext_->file_);
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
422
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
423 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
424 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
425 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
426 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
427 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
428 }
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
429
1731
b6f656a0bf2c "--logdir" creates a single log file instead of 3 separate files for errors/warnings/infos
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1551
diff changeset
430
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
431 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
432 {
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
433 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
434 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
435
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
436 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
437 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
438
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
439 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
440 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
441 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
442 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
443 loggingContext_->info_ = loggingContext_->file_.get();
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
444 }
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
445
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
446
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
447 InternalLogger::InternalLogger(const char* level,
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
448 const char* file,
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
449 int line) :
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
450 lock_(loggingMutex_),
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
451 stream_(&null_) // By default, logging to "/dev/null" is simulated
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
452 {
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
453 if (loggingContext_.get() == NULL)
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
454 {
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
455 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
456 return;
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
457 }
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
458
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
459 try
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
460 {
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
461 LogLevel l = StringToLogLevel(level);
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
462
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
463 if ((l == LogLevel_Info && !loggingContext_->infoEnabled_) ||
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
464 (l == LogLevel_Trace && !loggingContext_->traceEnabled_))
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
465 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
466 // 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
467 // 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
468 lock_.unlock();
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
469 return;
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
470 }
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
471
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
472 // 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
473 // this is a time-consuming operation
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
474 lock_.unlock();
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
475 std::string header;
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
476
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
477 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
478 boost::filesystem::path path(file);
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
479 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
480 boost::posix_time::time_duration duration = now.time_of_day();
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
481
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
482 /**
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
483 From Google Log documentation:
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
484
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
485 "Log lines have this form:
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
486
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
487 Lmmdd hh:mm:ss.uuuuuu threadid file:line] msg...
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
488
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
489 where the fields are defined as follows:
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
490
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
491 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
492 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
493 dd The day (zero padded)
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
494 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
495 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
496 file The file name
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
497 line The line number
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
498 msg The user-supplied message"
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
499
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
500 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
501 **/
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
502
2836
7133ad478eea fix Debian warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2505
diff changeset
503 char date[40];
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
504 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
505 level[0],
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
506 now.date().month().as_number(),
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
507 now.date().day().as_number(),
2483
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
508 static_cast<int>(duration.hours()),
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
509 static_cast<int>(duration.minutes()),
9c54c40eaf25 logging primitives for WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
510 static_cast<int>(duration.seconds()),
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
511 static_cast<int>(duration.fractional_seconds()));
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
512
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
513 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
514 }
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
515
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
516
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
517 // 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
518 // 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
519 // "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
520 // the mutex was unlocked.
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
521 lock_.lock();
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
522
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
523 if (loggingContext_.get() == NULL)
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
524 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
525 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
526 return;
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
527 }
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
528
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
529 switch (l)
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
530 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
531 case LogLevel_Error:
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
532 stream_ = loggingContext_->error_;
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
533 break;
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
534
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
535 case LogLevel_Warning:
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
536 stream_ = loggingContext_->warning_;
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
537 break;
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
538
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
539 case LogLevel_Info:
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
540 if (loggingContext_->infoEnabled_)
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
541 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
542 stream_ = loggingContext_->info_;
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
543 }
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
544
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
545 break;
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
546
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
547 case LogLevel_Trace:
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
548 if (loggingContext_->traceEnabled_)
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
549 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
550 stream_ = loggingContext_->info_;
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
551 }
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
552
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
553 break;
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
554
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
555 default:
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
556 throw OrthancException(ErrorCode_InternalError);
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
557 }
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
558
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
559 if (stream_ == &null_)
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
560 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
561 // 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
562 // "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
563 // mutex.
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
564 lock_.unlock();
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
565 }
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
566
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
567 (*stream_) << header;
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
568 }
2134
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
569 catch (...)
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
570 {
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
571 // 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
572 // memory. Fallback to a degraded mode.
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
573 stream_ = loggingContext_->error_;
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
574 (*stream_) << "E???? ??:??:??.?????? ] ";
ddc75c6c712d Avoid hard crash if not enough memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2015
diff changeset
575 }
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
576 }
1507
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
577
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
578
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
579 InternalLogger::~InternalLogger()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
580 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
581 if (stream_ != &null_)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
582 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
583 #if defined(_WIN32)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
584 *stream_ << "\r\n";
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
585 #else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
586 *stream_ << "\n";
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
587 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
588
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
589 stream_->flush();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
590 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
591 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
592
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
593
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
594 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
595 {
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
596 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
597
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
598 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
599 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
600 {
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
601 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
602 }
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
603 }
1485
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
604 }
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605 }
1488
c8763b603b0e flag for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1487
diff changeset
606
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
607 #endif // ORTHANC_ENABLE_LOGGING