]> git.tdb.fi Git - builder.git/blob - source/logger.h
Refactor logger to do message formatting internally
[builder.git] / source / logger.h
1 #ifndef LOGGER_H_
2 #define LOGGER_H_
3
4 #include <string>
5 #include <vector>
6 #include <msp/strings/format.h>
7
8 class Logger
9 {
10 private:
11         std::vector<std::string> enabled_channels;
12
13 public:
14         void enable_channel(const std::string &);
15         void disable_channel(const std::string &);
16         bool is_channel_enabled(const std::string &) const;
17
18         void log(const std::string &, const std::string &) const;
19
20         template<typename... Args>
21         void log(const std::string &, const std::string &, Args &&...) const;
22
23 private:
24         void print(const std::string &) const;
25 };
26
27 template<typename... Args>
28 void Logger::log(const std::string &chan, const std::string &fmt, Args &&... args) const
29 {
30         if(is_channel_enabled(chan))
31                 print(Msp::format(fmt, std::forward<Args>(args)...));
32 }
33
34 #endif