Skip to content

Commit d9358fc

Browse files
committed
Added new StreamProxy ctor to streamline code. Fixed copy-paste errors.
1 parent 265c189 commit d9358fc

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

inc/osvr/Util/Logger.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,14 @@ namespace util {
127127
class StreamProxy {
128128
public:
129129
StreamProxy(Logger &logger, LogLevel level)
130-
: logger_(logger), level_(level), os_(new std::ostringstream) {}
130+
: logger_(logger), level_(level),
131+
os_(new std::ostringstream) {}
132+
133+
StreamProxy(Logger &logger, LogLevel level, const char *msg)
134+
: logger_(logger), level_(level),
135+
os_(new std::ostringstream) {
136+
os_->operator<<(msg);
137+
}
131138

132139
/// destructor appends the finished stringstream at the end
133140
/// of the expression.
@@ -139,8 +146,8 @@ namespace util {
139146

140147
/// move construction
141148
StreamProxy(StreamProxy &&other)
142-
: logger_(other.logger_), level_(other.level_), os_(std::move(other.os_)),
143-
active_(other.active_) {
149+
: logger_(other.logger_), level_(other.level_),
150+
os_(std::move(other.os_)), active_(other.active_) {
144151
other.active_ = false;
145152
}
146153

src/osvr/Util/Logger.cpp

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -151,45 +151,31 @@ namespace util {
151151
}
152152

153153
Logger::StreamProxy Logger::trace(const char *msg) {
154-
StreamProxy proxy(*this, LogLevel::trace);
155-
proxy << msg;
156-
return proxy;
154+
return { *this, LogLevel::trace, msg };
157155
}
158156

159157
Logger::StreamProxy Logger::debug(const char *msg) {
160-
StreamProxy proxy(*this, LogLevel::trace);
161-
proxy << msg;
162-
return proxy;
158+
return { *this, LogLevel::debug, msg };
163159
}
164160

165161
Logger::StreamProxy Logger::info(const char *msg) {
166-
StreamProxy proxy(*this, LogLevel::trace);
167-
proxy << msg;
168-
return proxy;
162+
return { *this, LogLevel::info, msg };
169163
}
170164

171165
Logger::StreamProxy Logger::notice(const char *msg) {
172-
StreamProxy proxy(*this, LogLevel::trace);
173-
proxy << msg;
174-
return proxy;
166+
return { *this, LogLevel::notice, msg };
175167
}
176168

177169
Logger::StreamProxy Logger::warn(const char *msg) {
178-
StreamProxy proxy(*this, LogLevel::trace);
179-
proxy << msg;
180-
return proxy;
170+
return { *this, LogLevel::warn, msg };
181171
}
182172

183173
Logger::StreamProxy Logger::error(const char *msg) {
184-
StreamProxy proxy(*this, LogLevel::trace);
185-
proxy << msg;
186-
return proxy;
174+
return { *this, LogLevel::error, msg };
187175
}
188176

189177
Logger::StreamProxy Logger::critical(const char *msg) {
190-
StreamProxy proxy(*this, LogLevel::trace);
191-
proxy << msg;
192-
return proxy;
178+
return { *this, LogLevel::critical, msg };
193179
}
194180

195181
// logger.info() << ".." call style

0 commit comments

Comments
 (0)