From 77ca603e933af25088057dc5e26cfda84bde7147 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sun, 7 Feb 2016 22:18:10 +0100 Subject: Increase log message generation readability --- src/utility/logger.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/utility') diff --git a/src/utility/logger.h b/src/utility/logger.h index 30a6b44..6fd6613 100644 --- a/src/utility/logger.h +++ b/src/utility/logger.h @@ -10,15 +10,21 @@ namespace utility { class Logger { + #define FOR_EACH_ARGUMENT(...)\ + auto&& tmp = { (__VA_ARGS__, 0)... }; (void) tmp; + public: Logger(const int target_fd): buffer_(target_fd, std::ios::out), stream_(&this->buffer_) { } - void append(const std::string& msg) { + template + void append(const Args&... args) { std::lock_guard guard(this->write_mutex_); - this->stream_ << msg << std::endl; + FOR_EACH_ARGUMENT(this->stream_ << args); + + this->stream_ << std::endl; } // Forward the contents of a given standard output stream to the log target @@ -42,6 +48,7 @@ class Logger { std::ostream stream_; std::mutex write_mutex_; + #undef FOR_EACH_ARGUMENT }; } -- cgit v1.2.3