comparison Core/Logging.cpp @ 2243:2dbfdafc2512

Logger compatible with the Orthanc plugin SDK
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 23 Dec 2016 16:02:00 +0100
parents fd5875662670
children a3a65de1840f
comparison
equal deleted inserted replaced
2242:4e8e0ad2001c 2243:2dbfdafc2512
71 { 71 {
72 } 72 }
73 } 73 }
74 } 74 }
75 75
76 #else 76
77 #elif ORTHANC_ENABLE_LOGGING_PLUGIN == 1
78
79 /*********************************************************
80 * Logger compatible with the Orthanc plugin SDK
81 *********************************************************/
82
83 #include <boost/lexical_cast.hpp>
84
85 namespace Orthanc
86 {
87 namespace Logging
88 {
89 static OrthancPluginContext* context_ = NULL;
90
91 void Initialize(OrthancPluginContext* context)
92 {
93 context_ = context_;
94 }
95
96 InternalLogger::InternalLogger(const char* level,
97 const char* file /* ignored */,
98 int line /* ignored */) :
99 level_(level)
100 {
101 }
102
103 InternalLogger::~InternalLogger()
104 {
105 if (context_ != NULL)
106 {
107 if (level_ == "ERROR")
108 {
109 OrthancPluginLogError(context_, message_.c_str());
110 }
111 else if (level_ == "WARNING")
112 {
113 OrthancPluginLogWarning(context_, message_.c_str());
114 }
115 else if (level_ == "INFO")
116 {
117 OrthancPluginLogInfo(context_, message_.c_str());
118 }
119 }
120 }
121
122 InternalLogger& InternalLogger::operator<< (const std::string& message)
123 {
124 message_ += message;
125 return *this;
126 }
127
128 InternalLogger& InternalLogger::operator<< (const char* message)
129 {
130 message_ += std::string(message);
131 return *this;
132 }
133
134 InternalLogger& InternalLogger::operator<< (int message)
135 {
136 message_ += boost::lexical_cast<std::string>(message);
137 return *this;
138 }
139 }
140 }
141
142
143 #else /* ORTHANC_ENABLE_LOGGING_PLUGIN == 0 && ORTHANC_ENABLE_LOGGING == 1 */
77 144
78 /********************************************************* 145 /*********************************************************
79 * Internal logger of Orthanc, that mimics some 146 * Internal logger of Orthanc, that mimics some
80 * behavior from Google Log. 147 * behavior from Google Log.
81 *********************************************************/ 148 *********************************************************/