44 lines
859 B
C++
44 lines
859 B
C++
#ifndef _LOGGER_H_
|
|
#define _LOGGER_H_
|
|
|
|
#include <sstream>
|
|
#include <stdexcept>
|
|
#include <iostream>
|
|
#include <atomic>
|
|
|
|
class logger
|
|
{
|
|
private:
|
|
std::stringstream _logLine;
|
|
|
|
public:
|
|
logger();
|
|
|
|
template<typename... Args> void log(const char* s, const Args&... args)
|
|
{
|
|
_logLine.str("");
|
|
log_internal(s, args...);
|
|
}
|
|
|
|
private:
|
|
void log_internal(const char* s);
|
|
|
|
template<typename T, typename... Args> void log_internal(const char* s, const T& value, const Args&... args)
|
|
{
|
|
while (*s)
|
|
{
|
|
if (*s == '%' && *++s != '%')
|
|
{
|
|
_logLine << value;
|
|
return log_internal(s, args...);
|
|
}
|
|
_logLine << *s++;
|
|
}
|
|
throw std::runtime_error("extra arguments provided");
|
|
}
|
|
};
|
|
|
|
extern logger ulog;
|
|
|
|
#endif // _LOGGER_H_
|