annotate OrthancServer/Resources/Samples/CppHelpers/Logging/ILogger.h @ 5640:f7adfb22e20e

updated copyright, as Orthanc Team now replaces Osimis
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 30 May 2024 21:19:57 +0200
parents 48b8dae6dc77
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4829
c847b0dfd255 added missing copyright headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
1 /**
c847b0dfd255 added missing copyright headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
c847b0dfd255 added missing copyright headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
c847b0dfd255 added missing copyright headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
4 * Department, University Hospital of Liege, Belgium
5640
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
4829
c847b0dfd255 added missing copyright headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
8 *
c847b0dfd255 added missing copyright headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
9 * This program is free software: you can redistribute it and/or
c847b0dfd255 added missing copyright headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
10 * modify it under the terms of the GNU General Public License as
c847b0dfd255 added missing copyright headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
11 * published by the Free Software Foundation, either version 3 of the
c847b0dfd255 added missing copyright headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
12 * License, or (at your option) any later version.
c847b0dfd255 added missing copyright headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
13 *
c847b0dfd255 added missing copyright headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
14 * This program is distributed in the hope that it will be useful, but
c847b0dfd255 added missing copyright headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
c847b0dfd255 added missing copyright headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c847b0dfd255 added missing copyright headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
17 * General Public License for more details.
c847b0dfd255 added missing copyright headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
18 *
c847b0dfd255 added missing copyright headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
19 * You should have received a copy of the GNU General Public License
c847b0dfd255 added missing copyright headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
c847b0dfd255 added missing copyright headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
21 **/
c847b0dfd255 added missing copyright headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
22
c847b0dfd255 added missing copyright headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
23
3468
4c89b6160563 fix the fix of the fix (this time for good !)
Alain Mazy <alain@mazy.be>
parents: 3467
diff changeset
24 #pragma once
3460
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
25
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
26 #include <string>
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
27 #include <vector>
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
28 #include <boost/algorithm/string.hpp>
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
29 #include <boost/thread.hpp>
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
30
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
31 namespace OrthancHelpers
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
32 {
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
33
3654
427a13084241 OrthancHelpers::ShortenId to display shortened uuid in logs
Alain Mazy <alain@mazy.be>
parents: 3588
diff changeset
34
427a13084241 OrthancHelpers::ShortenId to display shortened uuid in logs
Alain Mazy <alain@mazy.be>
parents: 3588
diff changeset
35 inline std::string ShortenId(const std::string& orthancUuid)
427a13084241 OrthancHelpers::ShortenId to display shortened uuid in logs
Alain Mazy <alain@mazy.be>
parents: 3588
diff changeset
36 {
427a13084241 OrthancHelpers::ShortenId to display shortened uuid in logs
Alain Mazy <alain@mazy.be>
parents: 3588
diff changeset
37 size_t firstHyphenPos = orthancUuid.find_first_of('-');
427a13084241 OrthancHelpers::ShortenId to display shortened uuid in logs
Alain Mazy <alain@mazy.be>
parents: 3588
diff changeset
38 if (firstHyphenPos == std::string::npos)
427a13084241 OrthancHelpers::ShortenId to display shortened uuid in logs
Alain Mazy <alain@mazy.be>
parents: 3588
diff changeset
39 {
427a13084241 OrthancHelpers::ShortenId to display shortened uuid in logs
Alain Mazy <alain@mazy.be>
parents: 3588
diff changeset
40 return orthancUuid;
427a13084241 OrthancHelpers::ShortenId to display shortened uuid in logs
Alain Mazy <alain@mazy.be>
parents: 3588
diff changeset
41 }
427a13084241 OrthancHelpers::ShortenId to display shortened uuid in logs
Alain Mazy <alain@mazy.be>
parents: 3588
diff changeset
42 else
427a13084241 OrthancHelpers::ShortenId to display shortened uuid in logs
Alain Mazy <alain@mazy.be>
parents: 3588
diff changeset
43 {
427a13084241 OrthancHelpers::ShortenId to display shortened uuid in logs
Alain Mazy <alain@mazy.be>
parents: 3588
diff changeset
44 return orthancUuid.substr(0, firstHyphenPos);
427a13084241 OrthancHelpers::ShortenId to display shortened uuid in logs
Alain Mazy <alain@mazy.be>
parents: 3588
diff changeset
45 }
427a13084241 OrthancHelpers::ShortenId to display shortened uuid in logs
Alain Mazy <alain@mazy.be>
parents: 3588
diff changeset
46 }
427a13084241 OrthancHelpers::ShortenId to display shortened uuid in logs
Alain Mazy <alain@mazy.be>
parents: 3588
diff changeset
47
427a13084241 OrthancHelpers::ShortenId to display shortened uuid in logs
Alain Mazy <alain@mazy.be>
parents: 3588
diff changeset
48
3460
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
49 // Interface for loggers providing the same interface
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
50 // in Orthanc framework or in an Orthanc plugins.
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
51 // Furthermore, compared to the LOG and VLOG macros,
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
52 // these loggers will provide "contexts".
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
53 class ILogger
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
54 {
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
55 public:
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
56 virtual ~ILogger() {}
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
57 virtual void Trace(const char* message) = 0;
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
58 virtual void Trace(const std::string& message) = 0;
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
59 virtual void Info(const char* message) = 0;
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
60 virtual void Info(const std::string& message) = 0;
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
61 virtual void Warning(const char* message) = 0;
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
62 virtual void Warning(const std::string& message) = 0;
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
63 virtual void Error(const char* message) = 0;
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
64 virtual void Error(const std::string& message) = 0;
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
65
3588
eb48adfd931e forceLogContextChanges
Alain Mazy <alain@mazy.be>
parents: 3473
diff changeset
66 virtual void EnterContext(const char* message, bool forceLogContextChange = false) = 0;
eb48adfd931e forceLogContextChanges
Alain Mazy <alain@mazy.be>
parents: 3473
diff changeset
67 virtual void EnterContext(const std::string& message, bool forceLogContextChange = false) = 0;
eb48adfd931e forceLogContextChanges
Alain Mazy <alain@mazy.be>
parents: 3473
diff changeset
68 virtual void LeaveContext(bool forceLogContextChange = false) = 0;
3460
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
69 };
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
70
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
71
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
72 // Implements ILogger by providing contexts. Contexts defines
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
73 // the "call-stack" of the logs and are prepended to the log.
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
74 // check LogContext class for more details
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
75 class BaseLogger : public ILogger
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
76 {
3473
37e908965e5a improved detection of threads for ILogger
Alain Mazy <alain@mazy.be>
parents: 3468
diff changeset
77 #if ORTHANC_ENABLE_THREADS == 1
3460
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
78 boost::thread_specific_ptr<std::vector<std::string>> contexts_;
3466
b61e74e68d41 fix ILogger in non threaded environment (Emscripten)
Alain Mazy <alain@mazy.be>
parents: 3460
diff changeset
79 #else
3467
324f6b966c7a fix the fix
Alain Mazy <alain@mazy.be>
parents: 3466
diff changeset
80 std::auto_ptr<std::vector<std::string>> contexts_;
3466
b61e74e68d41 fix ILogger in non threaded environment (Emscripten)
Alain Mazy <alain@mazy.be>
parents: 3460
diff changeset
81 #endif
3460
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
82 bool logContextChanges_;
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
83
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
84 public:
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
85
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
86 BaseLogger()
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
87 : logContextChanges_(false)
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
88 {
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
89 }
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
90
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
91 void EnableLogContextChanges(bool enable)
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
92 {
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
93 logContextChanges_ = enable;
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
94 }
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
95
3588
eb48adfd931e forceLogContextChanges
Alain Mazy <alain@mazy.be>
parents: 3473
diff changeset
96 virtual void EnterContext(const char* message, bool forceLogContextChange = false)
3460
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
97 {
3588
eb48adfd931e forceLogContextChanges
Alain Mazy <alain@mazy.be>
parents: 3473
diff changeset
98 EnterContext(std::string(message), forceLogContextChange);
3460
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
99 }
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
100
3588
eb48adfd931e forceLogContextChanges
Alain Mazy <alain@mazy.be>
parents: 3473
diff changeset
101 virtual void EnterContext(const std::string& message, bool forceLogContextChange = false)
3460
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
102 {
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
103 if (!contexts_.get())
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
104 {
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
105 contexts_.reset(new std::vector<std::string>());
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
106 }
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
107 contexts_->push_back(message);
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
108
3588
eb48adfd931e forceLogContextChanges
Alain Mazy <alain@mazy.be>
parents: 3473
diff changeset
109 if (logContextChanges_ || forceLogContextChange)
3460
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
110 {
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
111 Info(".. entering");
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
112 }
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
113 }
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
114
3588
eb48adfd931e forceLogContextChanges
Alain Mazy <alain@mazy.be>
parents: 3473
diff changeset
115 virtual void LeaveContext(bool forceLogContextChange = false)
3460
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
116 {
3588
eb48adfd931e forceLogContextChanges
Alain Mazy <alain@mazy.be>
parents: 3473
diff changeset
117 if (logContextChanges_ || forceLogContextChange)
3460
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
118 {
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
119 Info(".. leaving");
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
120 }
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
121
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
122 contexts_->pop_back();
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
123 if (contexts_->size() == 0)
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
124 {
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
125 contexts_.reset(NULL);
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
126 }
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
127 }
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
128
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
129 protected:
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
130
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
131 virtual std::string GetContext()
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
132 {
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
133 if (contexts_.get() != NULL && contexts_->size() > 0)
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
134 {
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
135 return "|" + boost::algorithm::join(*contexts_, " | ") + "|";
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
136 }
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
137 else
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
138 {
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
139 return std::string("|");
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
140 }
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
141 }
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
142 };
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
143
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
144
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
145 /* RAII to set a Log context.
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
146 * Example:
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
147 * ILogger* logger = new OrthancPluginLogger(..);
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
148 * {
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
149 * LogContext logContext(logger, "A");
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
150 * {
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
151 * LogContext nestedLogContext(logger, "B");
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
152 * logger->Error("out of memory");
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
153 * }
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
154 * }
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
155 * will produce:
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
156 * |A | B| out of memory
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
157 *
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
158 * furthermore, if LogContextChanges are enabled in the BaseLogger,
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
159 * you'll get;
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
160 * |A| .. entering
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
161 * |A | B| .. entering
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
162 * |A | B| out of memory
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
163 * |A | B| .. leaving
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
164 * |A| .. leaving
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
165 */
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
166 class LogContext
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
167 {
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
168 ILogger* logger_;
3588
eb48adfd931e forceLogContextChanges
Alain Mazy <alain@mazy.be>
parents: 3473
diff changeset
169 bool forceLogContextChange_;
3460
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
170 public:
3588
eb48adfd931e forceLogContextChanges
Alain Mazy <alain@mazy.be>
parents: 3473
diff changeset
171 LogContext(ILogger* logger, const char* context, bool forceLogContextChange = false) :
eb48adfd931e forceLogContextChanges
Alain Mazy <alain@mazy.be>
parents: 3473
diff changeset
172 logger_(logger),
eb48adfd931e forceLogContextChanges
Alain Mazy <alain@mazy.be>
parents: 3473
diff changeset
173 forceLogContextChange_(forceLogContextChange)
3460
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
174 {
3588
eb48adfd931e forceLogContextChanges
Alain Mazy <alain@mazy.be>
parents: 3473
diff changeset
175 logger_->EnterContext(context, forceLogContextChange_);
3460
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
176 }
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
177
3588
eb48adfd931e forceLogContextChanges
Alain Mazy <alain@mazy.be>
parents: 3473
diff changeset
178 LogContext(ILogger* logger, const std::string& context, bool forceLogContextChange = false) :
eb48adfd931e forceLogContextChanges
Alain Mazy <alain@mazy.be>
parents: 3473
diff changeset
179 logger_(logger),
eb48adfd931e forceLogContextChanges
Alain Mazy <alain@mazy.be>
parents: 3473
diff changeset
180 forceLogContextChange_(forceLogContextChange)
3460
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
181 {
3588
eb48adfd931e forceLogContextChanges
Alain Mazy <alain@mazy.be>
parents: 3473
diff changeset
182 logger_->EnterContext(context, forceLogContextChange_);
3460
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
183 }
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
184
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
185 ~LogContext()
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
186 {
3588
eb48adfd931e forceLogContextChanges
Alain Mazy <alain@mazy.be>
parents: 3473
diff changeset
187 logger_->LeaveContext(forceLogContextChange_);
3460
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
188 }
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
189
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
190 };
fbe22748cd9c added logging OrthancHelpers
Alain Mazy <alain@mazy.be>
parents:
diff changeset
191 }