]> git.tdb.fi Git - builder.git/blobdiff - source/logger.h
Refactor logger to do message formatting internally
[builder.git] / source / logger.h
index 64c131544c4cef1995ec8c8b3786b7355f90ee36..3a10f0e89177e10c071b97cd389c79e4d46a1404 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <string>
 #include <vector>
+#include <msp/strings/format.h>
 
 class Logger
 {
@@ -12,8 +13,22 @@ private:
 public:
        void enable_channel(const std::string &);
        void disable_channel(const std::string &);
+       bool is_channel_enabled(const std::string &) const;
 
        void log(const std::string &, const std::string &) const;
+
+       template<typename... Args>
+       void log(const std::string &, const std::string &, Args &&...) const;
+
+private:
+       void print(const std::string &) const;
 };
 
+template<typename... Args>
+void Logger::log(const std::string &chan, const std::string &fmt, Args &&... args) const
+{
+       if(is_channel_enabled(chan))
+               print(Msp::format(fmt, std::forward<Args>(args)...));
+}
+
 #endif