61 lines
1.4 KiB
C
61 lines
1.4 KiB
C
|
#ifndef CHIP8_LOGGER_H
|
||
|
#define CHIP8_LOGGER_H
|
||
|
|
||
|
#include <iostream>
|
||
|
#include <string>
|
||
|
#include "date.h"
|
||
|
|
||
|
enum LogType {
|
||
|
INFO,
|
||
|
DEBUG,
|
||
|
WARN,
|
||
|
ERROR
|
||
|
};
|
||
|
class Logger {
|
||
|
private:
|
||
|
static const char* logTypeToString(LogType logType) {
|
||
|
switch (logType) {
|
||
|
case LogType::INFO:
|
||
|
return "INFO";
|
||
|
case LogType::DEBUG:
|
||
|
return "DEBUG";
|
||
|
case LogType::WARN:
|
||
|
return "WARN";
|
||
|
case LogType::ERROR:
|
||
|
return "ERROR";
|
||
|
}
|
||
|
|
||
|
return "";
|
||
|
}
|
||
|
public:
|
||
|
template<typename... Args>
|
||
|
static void log(LogType logType, Args&&... args) {
|
||
|
std::ostream& stream = (logType == LogType::ERROR) ? std::cerr : std::cout;
|
||
|
stream << "[" << logTypeToString(logType) << "] [" << Date::now().to_string() << "]";
|
||
|
((stream << " " << args), ...);
|
||
|
stream << std::endl;
|
||
|
}
|
||
|
|
||
|
template<typename... Args>
|
||
|
static void info(Args&&... args) {
|
||
|
log(LogType::INFO, std::forward<Args>(args)...);
|
||
|
}
|
||
|
|
||
|
template<typename... Args>
|
||
|
static void debug(Args&&... args) {
|
||
|
log(LogType::DEBUG, std::forward<Args>(args)...);
|
||
|
}
|
||
|
|
||
|
template<typename... Args>
|
||
|
static void warn(Args&&... args) {
|
||
|
log(LogType::WARN, std::forward<Args>(args)...);
|
||
|
}
|
||
|
|
||
|
template<typename... Args>
|
||
|
static void error(Args&&... args) {
|
||
|
log(LogType::ERROR, std::forward<Args>(args)...);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
#endif //CHIP8_LOGGER_H
|