I have a file logger like this:
struct file_logger{
logger &__logger;
const int32_t __log_fd;
friend class logger;
template <severity sev, typename... Args>
inline void log(Args... args);
template <severity sev, char sep, typename... Args>
inline void log_s(int32_t log_fd, Args... args);
private:
file_logger(logger &l, const int32_t &fd) : __logger(l), __log_fd(fd) {}
};
template <severity sev, typename... Args>
inline void file_logger::log(Args... args){
__logger.log<sev>(__log_fd, args...);
}
template <severity sev, char sep, typename... Args>
inline void file_logger::log_s(int32_t log_fd, Args... args){
__logger.log_s<sev, sep>(__log_fd, args...);
}
I would like to have special member like info
for instance which will log for a specific severity. I want this because it is frustrating to write log<severity::INFO>
everytime I want to use log some info.
so I can have
/*assume info declared in file_logger*/
template<typename... Args>
inline void file_logger::info(Args... args){
__logger.log<severity::INFO>(args...);
}
So I have decided to add some common severities like info
,warn
,error
,debug
. However, I also want to have a compile time check that the severity level exists in the enum for which the function is defined. In case the severity is not defined. I want to have a compilation error if and only if the function is called. Otherwise, I would like the compiler to ignore the template.
I am using c++17.