aboutsummaryrefslogtreecommitdiff
path: root/src/utility/logger.h
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-12-24 00:11:06 +0100
committerAdrian Kummerlaender2015-12-24 00:11:06 +0100
commitbaf30b7b83822b7d6efd0c16761b8e42a1e96101 (patch)
tree33eebf92abdde2f2cfbba138bb506529a332955e /src/utility/logger.h
parentcce63aca270c51fb3ce9790438e3c23864de0a87 (diff)
downloadchange-baf30b7b83822b7d6efd0c16761b8e42a1e96101.tar
change-baf30b7b83822b7d6efd0c16761b8e42a1e96101.tar.gz
change-baf30b7b83822b7d6efd0c16761b8e42a1e96101.tar.bz2
change-baf30b7b83822b7d6efd0c16761b8e42a1e96101.tar.lz
change-baf30b7b83822b7d6efd0c16761b8e42a1e96101.tar.xz
change-baf30b7b83822b7d6efd0c16761b8e42a1e96101.tar.zst
change-baf30b7b83822b7d6efd0c16761b8e42a1e96101.zip
Match namespace and directory structure
Diffstat (limited to 'src/utility/logger.h')
-rw-r--r--src/utility/logger.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/utility/logger.h b/src/utility/logger.h
new file mode 100644
index 0000000..475f33d
--- /dev/null
+++ b/src/utility/logger.h
@@ -0,0 +1,44 @@
+#ifndef CHANGE_SRC_LOGGER_H_
+#define CHANGE_SRC_LOGGER_H_
+
+#include <ext/stdio_filebuf.h>
+
+#include <boost/process.hpp>
+
+#include <iostream>
+
+namespace utility {
+
+class Logger {
+ public:
+ Logger(const int target_fd):
+ buffer_(target_fd, std::ios::out),
+ stream_(&this->buffer_) { }
+
+ void append(const std::string& msg) {
+ this->stream_ << msg << std::endl;
+ }
+
+ // Forward the contents of a given standard output stream to the log target
+ //
+ // While `this->stream_ << stream.rdbuf()` would be more effective it sadly
+ // does not work with `boost::process::pistream` due to a broken pipe error
+ // in conjunction with the required `boost::process::capture_stream` context
+ // flag.
+ //
+ void forward(boost::process::pistream& stream) {
+ this->stream_ << std::string(
+ (std::istreambuf_iterator<char>(stream)),
+ (std::istreambuf_iterator<char>())
+ );
+ }
+
+ private:
+ __gnu_cxx::stdio_filebuf<char> buffer_;
+ std::ostream stream_;
+
+};
+
+}
+
+#endif // CHANGE_SRC_LOGGER_H_