cpputil/include/logger.h

43 lines
810 B
C++

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