2016-02-08 05:56:52 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
|
|
|
#include <ctime>
|
|
|
|
#include <iomanip>
|
|
|
|
|
|
|
|
class Logger
|
|
|
|
{
|
|
|
|
public:
|
2016-02-11 06:34:49 +08:00
|
|
|
Logger(Logger& other) = delete;
|
|
|
|
Logger(Logger&& other) = delete;
|
|
|
|
|
|
|
|
private:
|
2016-02-08 05:56:52 +08:00
|
|
|
Logger() = default;
|
|
|
|
|
|
|
|
// TODO logger name support
|
|
|
|
|
|
|
|
// TODO level support
|
|
|
|
|
|
|
|
// TODO handlers support:
|
|
|
|
// * log format support
|
2016-02-11 06:34:49 +08:00
|
|
|
|
|
|
|
// TODO merge with debug/log.hpp
|
|
|
|
|
|
|
|
public:
|
|
|
|
static Logger& instance()
|
2016-02-08 05:56:52 +08:00
|
|
|
{
|
2016-02-11 06:34:49 +08:00
|
|
|
static Logger logger;
|
|
|
|
return logger;
|
2016-02-08 05:56:52 +08:00
|
|
|
}
|
|
|
|
|
2016-02-11 06:34:49 +08:00
|
|
|
void info(const std::string& text)
|
2016-02-08 05:56:52 +08:00
|
|
|
{
|
|
|
|
stdout_log(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void stdout_log(const std::string& text)
|
|
|
|
{
|
|
|
|
auto now = std::time(nullptr);
|
|
|
|
std::cout << std::put_time(std::gmtime(&now), "[%F %T]: ")
|
|
|
|
<< text << std::endl;
|
|
|
|
}
|
|
|
|
};
|
2016-02-11 06:34:49 +08:00
|
|
|
|
|
|
|
#ifdef NOT_LOG_INFO
|
|
|
|
# define LOG_INFO(_)
|
|
|
|
#else
|
|
|
|
# define LOG_INFO(_MESSAGE_) Logger::instance().info(_MESSAGE_);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|