aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/change_log.cc10
-rw-r--r--src/utility/logger.h11
2 files changed, 14 insertions, 7 deletions
diff --git a/src/change_log.cc b/src/change_log.cc
index a060c91..c8dd8a1 100644
--- a/src/change_log.cc
+++ b/src/change_log.cc
@@ -61,20 +61,20 @@ int rename(const char* old_path, const char* new_path) {
tracker->track(old_path);
}
- logger->append("renamed '" + std::string(old_path) + "' to '" + std::string(new_path) + "'");
+ logger->append("renamed '", old_path, "' to '", new_path, "'");
return actual::rename(old_path, new_path);
}
int rmdir(const char* path) {
- logger->append("removed directory '" + std::string(path) + "'");
+ logger->append("removed directory '", path, "'");
return actual::rmdir(path);
}
int unlink(const char* path) {
if ( utility::is_regular_file(path) ) {
- logger->append("remove '" + std::string(path) + "'");
+ logger->append("remove '", path, "'");
}
return actual::unlink(path);
@@ -82,9 +82,9 @@ int unlink(const char* path) {
int unlinkat(int dirfd, const char* path, int flags) {
if ( dirfd == AT_FDCWD ) {
- logger->append("removed '" + std::string(path) + "'");
+ logger->append("removed '", path, "'");
} else {
- logger->append("removed '" + utility::get_file_name(dirfd) + path + "'");
+ logger->append("removed '", utility::get_file_name(dirfd), path, "'");
}
return actual::unlinkat(dirfd, path, flags);
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 <typename... Args>
+ void append(const Args&... args) {
std::lock_guard<std::mutex> 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
};
}