annotate Core/Logging.cpp @ 2062:40ffd0e8676a

generation of etag in ServeFolders
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 02 Jul 2016 15:09:03 +0200
parents bcc575732aef
children ddc75c6c712d
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
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * 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
7 * 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
8 * 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
9 * License, or (at your option) any later version.
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * 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
12 * 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
13 * 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
14 * 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
15 * 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
16 * 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
17 * 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
18 * 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
19 * 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
20 * 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
21 * in the program, then also delete it here.
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * 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
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * 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
29 * 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
30 **/
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 #include "PrecompiledHeaders.h"
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "Logging.h"
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
1551
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
36 #if ORTHANC_ENABLE_LOGGING != 1
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
37
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
38 namespace Orthanc
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
39 {
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
40 namespace Logging
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
41 {
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
42 void Initialize()
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
43 {
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 void Finalize()
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
47 {
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
48 }
1485
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
50 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
51 {
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 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
55 {
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
1551
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
58 void EnableInfoLevel(bool enabled)
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
59 {
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
60 }
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
61
1551
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
62 void EnableTraceLevel(bool enabled)
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
63 {
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
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
66 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
67 {
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
1551
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
70 void SetTargetFolder(const std::string& path)
0dba274074eb standalone logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1507
diff changeset
71 {
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
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
76 #else
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
77
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
78 /*********************************************************
2014
e39a2657f1c6 Dropped support of Google Log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
79 * Internal logger of Orthanc, that mimics some
e39a2657f1c6 Dropped support of Google Log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
80 * behavior from Google Log.
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
81 *********************************************************/
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
82
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
83 #include "OrthancException.h"
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
84 #include "Enumerations.h"
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
85 #include "Toolbox.h"
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
86
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
87 #include <fstream>
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
88 #include <boost/filesystem.hpp>
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
89 #include <boost/thread.hpp>
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
90
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
91 #if BOOST_HAS_DATE_TIME == 1
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
92 # include <boost/date_time/posix_time/posix_time.hpp>
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
93 #else
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
94 # error Boost::date_time is required
1487
23083810d543 removal of unneeded static libraries
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1485
diff changeset
95 #endif
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
96
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
97
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
98 namespace
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
99 {
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
100 struct LoggingContext
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
101 {
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
102 bool infoEnabled_;
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
103 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
104 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
105 std::string targetFolder_;
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
106
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
107 std::ostream* error_;
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
108 std::ostream* warning_;
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
109 std::ostream* info_;
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
110
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
111 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
112
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
113 LoggingContext() :
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
114 infoEnabled_(false),
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
115 traceEnabled_(false),
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
116 error_(&std::cerr),
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
117 warning_(&std::cerr),
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
118 info_(&std::cerr)
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
119 {
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
120 }
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
121 };
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
122 }
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
123
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
124
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
125
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
126 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
127 static boost::mutex loggingMutex_;
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
128
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
129
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
130
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
131 namespace Orthanc
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
132 {
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
133 namespace Logging
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
134 {
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
135 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
136 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
137 const std::string& suffix,
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
138 const std::string& directory)
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
139 {
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
140 /**
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
141 From Google Log documentation:
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
142
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
143 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
144 "<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
145 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
146 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
147
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
148 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
149 **/
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
150
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
151 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
152 boost::filesystem::path root(directory);
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
153 boost::filesystem::path exe(Toolbox::GetPathToExecutable());
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
154
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
155 if (!boost::filesystem::exists(root) ||
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
156 !boost::filesystem::is_directory(root))
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
157 {
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
158 throw OrthancException(ErrorCode_CannotWriteFile);
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
159 }
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
160
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
161 char date[64];
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
162 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
163 static_cast<int>(now.date().year()),
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
164 now.date().month().as_number(),
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
165 now.date().day().as_number(),
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
166 now.time_of_day().hours(),
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
167 now.time_of_day().minutes(),
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
168 now.time_of_day().seconds(),
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
169 Toolbox::GetProcessId());
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
170
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
171 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
172
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
173 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
174 link = (root / (programName + ".log" + suffix));
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
175 }
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
176
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
177
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
178 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
179 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
180 const std::string& directory)
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
181 {
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
182 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
183 GetLogPath(log, link, suffix, directory);
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
184
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
185 #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
186 boost::filesystem::remove(link);
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
187 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
188 #endif
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
189
1494
a13581480b1f fix mingw build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1490
diff changeset
190 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
191 }
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
192
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
193
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
194 void Initialize()
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
195 {
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
196 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
197 loggingContext_.reset(new LoggingContext);
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
198 }
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
199
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
200 void Finalize()
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
201 {
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
202 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
203 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
204 }
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
205
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
206 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
207 {
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
208 // 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
209 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
210
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
211 {
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
212 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
213 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
214 {
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
215 return;
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
216 }
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
217 else
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
218 {
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
219 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
220
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
221 // 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
222 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
223 }
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
224 }
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
225
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
226 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
227 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
228
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
229 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
230 {
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
231 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
232 }
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
233 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
234 {
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
235 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
236 }
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
237 }
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
238
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
239 void EnableInfoLevel(bool enabled)
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
240 {
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
241 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
242 assert(loggingContext_.get() != NULL);
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
243
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
244 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
245
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
246 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
247 {
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
248 // 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
249 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
250 }
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
251 }
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
252
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
253 void EnableTraceLevel(bool enabled)
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
254 {
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
255 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
256 assert(loggingContext_.get() != NULL);
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
257
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
258 loggingContext_->traceEnabled_ = enabled;
1489
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 if (enabled)
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
261 {
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
262 // 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
263 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
264 }
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
265 }
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
266
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
267
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
268 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
269 {
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
270 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
271 !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
272 {
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
273 throw OrthancException(ErrorCode_CannotWriteFile);
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
274 }
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
275 }
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
276
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
277 void SetTargetFolder(const std::string& path)
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
278 {
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
279 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
280 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
281
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
282 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
283 CheckFile(loggingContext_->file_);
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
284
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
285 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
286 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
287 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
288 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
289 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
290 }
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
291
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
292
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
293 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
294 {
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
295 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
296 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
297
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
298 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
299 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
300
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
301 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
302 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
303 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
304 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
305 loggingContext_->info_ = loggingContext_->file_.get();
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
306 }
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
307
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
308
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
309 InternalLogger::InternalLogger(const char* level,
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
310 const char* file,
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
311 int line) :
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
312 lock_(loggingMutex_),
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
313 stream_(&null_) // By default, logging to "/dev/null" is simulated
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
314 {
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
315 if (loggingContext_.get() == NULL)
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
316 {
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
317 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
318 return;
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
319 }
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
320
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
321 LogLevel l = StringToLogLevel(level);
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
322
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
323 if ((l == LogLevel_Info && !loggingContext_->infoEnabled_) ||
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
324 (l == LogLevel_Trace && !loggingContext_->traceEnabled_))
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
325 {
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
326 // This logging level is disabled, directly exit and unlock
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
327 // the mutex to speed-up things. The stream is set to "/dev/null"
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
328 lock_.unlock();
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
329 return;
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
330 }
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
331
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
332 // Compute the header of the line, temporary release the lock as
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
333 // this is a time-consuming operation
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
334 lock_.unlock();
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
335 std::string header;
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
336
1489
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 boost::filesystem::path path(file);
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
339 boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time();
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
340 boost::posix_time::time_duration duration = now.time_of_day();
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
341
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
342 /**
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
343 From Google Log documentation:
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
344
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
345 "Log lines have this form:
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
346
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
347 Lmmdd hh:mm:ss.uuuuuu threadid file:line] msg...
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
348
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
349 where the fields are defined as follows:
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
350
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
351 L A single character, representing the log level (eg 'I' for INFO)
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
352 mm The month (zero padded; ie May is '05')
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
353 dd The day (zero padded)
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
354 hh:mm:ss.uuuuuu Time in hours, minutes and fractional seconds
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
355 threadid The space-padded thread ID as returned by GetTID() (this matches the PID on Linux)
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
356 file The file name
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
357 line The line number
1490
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
358 msg The user-supplied message"
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
359
596927722403 support of --logdir by the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1489
diff changeset
360 In this implementation, "threadid" is not printed.
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
361 **/
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
362
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
363 char date[32];
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
364 sprintf(date, "%c%02d%02d %02d:%02d:%02d.%06d ",
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
365 level[0],
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
366 now.date().month().as_number(),
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
367 now.date().day().as_number(),
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
368 duration.hours(),
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
369 duration.minutes(),
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
370 duration.seconds(),
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
371 static_cast<int>(duration.fractional_seconds()));
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
372
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
373 header = std::string(date) + path.filename().string() + ":" + boost::lexical_cast<std::string>(line) + "] ";
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
374 }
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
375
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
376
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
377 // The header is computed, we now re-lock the mutex to access
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
378 // the stream objects. Pay attention that "loggingContext_",
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
379 // "infoEnabled_" or "traceEnabled_" might have changed while
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
380 // the mutex was unlocked.
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
381 lock_.lock();
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
382
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
383 if (loggingContext_.get() == NULL)
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
384 {
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
385 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
386 return;
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
387 }
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
388
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
389 switch (l)
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
390 {
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
391 case LogLevel_Error:
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
392 stream_ = loggingContext_->error_;
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
393 break;
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
394
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
395 case LogLevel_Warning:
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 stream_ = loggingContext_->warning_;
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
397 break;
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
398
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
399 case LogLevel_Info:
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
400 if (loggingContext_->infoEnabled_)
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
401 {
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
402 stream_ = loggingContext_->info_;
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
403 }
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
404
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
405 break;
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
406
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
407 case LogLevel_Trace:
2015
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_->traceEnabled_)
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
409 {
2015
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
410 stream_ = loggingContext_->info_;
1495
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
411 }
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
412
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
413 break;
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
414
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
415 default:
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
416 throw OrthancException(ErrorCode_InternalError);
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
417 }
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
418
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
419 if (stream_ == &null_)
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
420 {
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
421 // The logging is disabled for this level. The stream is the
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
422 // "null_" member of this object, so we can release the global
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
423 // mutex.
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
424 lock_.unlock();
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
425 }
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
426
fbe40117eb21 improve the performance of the internal logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1494
diff changeset
427 (*stream_) << header;
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
428 }
1507
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
429
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
430
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
431 InternalLogger::~InternalLogger()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
432 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
433 if (stream_ != &null_)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
434 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
435 #if defined(_WIN32)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
436 *stream_ << "\r\n";
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
437 #else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
438 *stream_ << "\n";
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
439 #endif
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
440
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
441 stream_->flush();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
442 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
443 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
diff changeset
444
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1495
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 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
447 {
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
448 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
449
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
450 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
451 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
452 {
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
453 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
454 }
bcc575732aef New option "--logfile" to output the Orthanc log to the given file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2014
diff changeset
455 }
1485
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 }
27661b33f624 Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 }
1488
c8763b603b0e flag for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1487
diff changeset
458
1489
1389834e130f basic logger
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1488
diff changeset
459 #endif // ORTHANC_ENABLE_LOGGING