44 void log(std::string message, LogLevel level)
override
55 case LogLevel::Warning:
61 case LogLevel::Critical:
65 std::cerr << std::string(
"(") + timestamp() + std::string(
") [") + prefix + std::string(
"] ") + message << std::endl;
69 static std::string timestamp()
76#if defined(_MSC_VER) || defined(__MINGW32__)
77#ifdef CROW_USE_LOCALTIMEZONE
78 localtime_s(&my_tm, &t);
83#ifdef CROW_USE_LOCALTIMEZONE
84 localtime_r(&t, &my_tm);
90 size_t sz = strftime(date,
sizeof(date),
"%Y-%m-%d %H:%M:%S", &my_tm);
91 return std::string(date, date + sz);
103#ifdef CROW_ENABLE_LOGGING
104 if (level_ >= get_current_log_level())
106 get_handler_ref()->log(stringstream_.str(), level_);
113 logger& operator<<(T
const& value)
115#ifdef CROW_ENABLE_LOGGING
116 if (level_ >= get_current_log_level())
118 stringstream_ << value;
125 static void setLogLevel(LogLevel level) { get_log_level_ref() = level; }
127 static void setHandler(
ILogHandler* handler) { get_handler_ref() = handler; }
129 static LogLevel get_current_log_level() {
return get_log_level_ref(); }
133 static LogLevel& get_log_level_ref()
135 static LogLevel current_level =
static_cast<LogLevel
>(CROW_LOG_LEVEL);
136 return current_level;
141 static ILogHandler* current_handler = &default_handler;
142 return current_handler;
146 std::ostringstream stringstream_;