16 #include <boost/format.hpp> 24 static std::string getCurrentTime() {
25 std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
26 auto now_ms = now.time_since_epoch();
27 auto now_sec = std::chrono::duration_cast<std::chrono::seconds>(now_ms);
28 auto tm_ms = std::chrono::duration_cast<std::chrono::milliseconds>(now_ms - now_sec);
30 std::time_t currentTime = std::chrono::system_clock::to_time_t(now);
31 struct tm* localTime = std::localtime(¤tTime);
33 return (boost::format(
"%02i:%02i:%02i.%03i") % localTime->tm_hour % localTime->tm_min %
34 localTime->tm_sec % tm_ms.count())
38 NullLogger* NullLogger::instance_ =
nullptr;
40 NullLogger& NullLogger::getInstance() noexcept {
42 instance_ =
new NullLogger();
46 Logger* Logger::instance_ =
nullptr;
48 Logger& Logger::getInstance() noexcept {
50 instance_ =
new Logger();
55 LoggerProxy::~LoggerProxy() { std::cout << std::endl; }
57 LoggerProxy Logger::trace() noexcept {
58 std::cout <<
"[" << getCurrentTime() <<
"] [trace] ";
62 LoggerProxy Logger::debug() noexcept {
63 std::cout <<
"[" << getCurrentTime() <<
"] [debug] ";
67 LoggerProxy Logger::info() noexcept {
68 std::cout <<
"[" << getCurrentTime() <<
"] [info] ";
72 LoggerProxy Logger::warning() noexcept {
73 std::cout <<
"[" << getCurrentTime() <<
"] [warning] ";
77 LoggerProxy Logger::error() noexcept {
78 std::cout <<
"[" << getCurrentTime() <<
"] [error] ";
82 LoggerProxy Logger::fatal() noexcept {
83 std::cout <<
"[" << getCurrentTime() <<
"] [fatal] ";
87 bool LoggingIsEnabled =
false;
static void enable() noexcept
Disable logging.
Namespace of the serialbox library.