Files
libuvosunwrap/log.h
uvos 38680f029c add logging engine
add options to control harris algorithum
2020-10-27 20:59:19 +01:00

77 lines
917 B
C++

#pragma once
#include <iostream>
#include <string>
class Log
{
public:
enum Level
{
DEBUG,
INFO,
WARN,
ERROR
};
private:
bool opened = false;
Level msglevel = DEBUG;
inline std::string getLabel(Level level)
{
std::string label;
switch(level)
{
case DEBUG:
label = "DEBUG";
break;
case INFO:
label = "INFO ";
break;
case WARN:
label = "WARN ";
break;
case ERROR:
label = "ERROR";
break;
}
return label;
}
public:
inline static bool headers = false;
inline static Level level = WARN;
Log() {}
Log(Level type)
{
msglevel = type;
if(headers)
{
operator << ("["+getLabel(type)+"]");
}
}
~Log()
{
if(opened)
{
std::cout<<'\n';
}
opened = false;
}
template<class T> Log &operator<<(const T &msg)
{
if(msglevel >= level)
{
std::cout<<msg;
opened = true;
}
return *this;
}
};