Last active
September 9, 2019 08:17
-
-
Save prostoiChelovek/6089e3a3e2bb706f8c0043fa220d8fa7 to your computer and use it in GitHub Desktop.
Simple log function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
enum LogType { | |
INFO, WARNING, ERROR | |
}; | |
template<typename T> | |
void coutMany(T t) { | |
std::cout << t << " " << std::endl; | |
} | |
template<typename T, typename... Args> | |
void coutMany(T t, Args... args) { // recursive variadic function | |
std::cout << t << " " << std::flush; | |
coutMany(args...); | |
} | |
template<typename T> | |
void cerrMany(T t) { | |
std::cerr << t << " " << std::endl; | |
} | |
template<typename T, typename... Args> | |
void cerrMany(T t, Args... args) { // recursive variadic function | |
std::cerr << t << " " << std::flush; | |
cerrMany(args...); | |
} | |
template<typename T, typename... Args> | |
void log(int type, T t, Args... args) { | |
switch (type) { | |
case INFO: | |
std::cout << "\033[;32mINFO:\033[0m "; | |
coutMany(t, args...); | |
break; | |
case WARNING: | |
std::cout << "\033[1;33mWARNING:\033[0m "; | |
coutMany(t, args...); | |
break; | |
case ERROR: | |
std::cerr << "\033[1;31mERROR:\033[0m "; | |
cerrMany(t, args...); | |
break; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment