51 lines
958 B
C++
51 lines
958 B
C++
#ifndef LIBRARY_LOG_H
|
|
#define LIBRARY_LOG_H
|
|
|
|
#include <string>
|
|
#include <sstream>
|
|
|
|
enum LogLevel{
|
|
DEBUG = 1,
|
|
INFO = 2,
|
|
WARNING = 3,
|
|
ERROR = 4,
|
|
CRITICAL = 5,
|
|
OFF = 6
|
|
};
|
|
|
|
/**
|
|
* log the messgae with logLevel and timestamp
|
|
* @author Julian Hinxlage
|
|
* @since 0.1.0
|
|
*/
|
|
void log(LogLevel level, const std::string &msg);
|
|
|
|
|
|
template<typename T>
|
|
static void buildString(std::stringstream &stream, T t) {
|
|
stream << t;
|
|
}
|
|
|
|
template<typename T, typename... Ts>
|
|
static void buildString(std::stringstream &stream, T t, Ts... ts) {
|
|
stream << t;
|
|
buildString(stream, ts...);
|
|
}
|
|
|
|
template<typename... T>
|
|
static void log(LogLevel level, T... t){
|
|
std::stringstream stream;
|
|
buildString(stream, t...);
|
|
log(level, stream.str());
|
|
}
|
|
|
|
|
|
/**
|
|
* set the logLevel, the log function will use this to determine if the message is logged
|
|
* @author Julian Hinxlage
|
|
* @since 0.1.0
|
|
*/
|
|
void setLogLevel(LogLevel level);
|
|
|
|
#endif //LIBRARY_LOG_H
|