10#include "crow/settings.h"
35 virtual void log(std::string message, LogLevel level) = 0;
40 void log(std::string message, LogLevel )
override {
49 static std::string timestamp()
56#if defined(_MSC_VER) || defined(__MINGW32__)
62 size_t sz = strftime(date,
sizeof(date),
"%Y-%m-%d %H:%M:%S", &my_tm);
63 return std::string(date, date+sz);
69 logger(std::string prefix, LogLevel level) : level_(level) {
70 #ifdef CROW_ENABLE_LOGGING
71 stringstream_ <<
"(" << timestamp() <<
") [" << prefix <<
"] ";
76 #ifdef CROW_ENABLE_LOGGING
77 if(level_ >= get_current_log_level()) {
78 stringstream_ << std::endl;
79 get_handler_ref()->log(stringstream_.str(), level_);
86 logger& operator<<(T
const &value) {
88 #ifdef CROW_ENABLE_LOGGING
89 if(level_ >= get_current_log_level()) {
90 stringstream_ << value;
97 static void setLogLevel(LogLevel level) {
98 get_log_level_ref() = level;
102 get_handler_ref() = handler;
105 static LogLevel get_current_log_level() {
106 return get_log_level_ref();
111 static LogLevel& get_log_level_ref()
113 static LogLevel current_level =
static_cast<LogLevel
>(CROW_LOG_LEVEL);
114 return current_level;
119 static ILogHandler* current_handler = &default_handler;
120 return current_handler;
124 std::ostringstream stringstream_;
129#define CROW_LOG_CRITICAL \
130 if (crow::logger::get_current_log_level() <= crow::LogLevel::Critical) \
131 crow::logger("CRITICAL", crow::LogLevel::Critical)
132#define CROW_LOG_ERROR \
133 if (crow::logger::get_current_log_level() <= crow::LogLevel::Error) \
134 crow::logger("ERROR ", crow::LogLevel::Error)
135#define CROW_LOG_WARNING \
136 if (crow::logger::get_current_log_level() <= crow::LogLevel::Warning) \
137 crow::logger("WARNING ", crow::LogLevel::Warning)
138#define CROW_LOG_INFO \
139 if (crow::logger::get_current_log_level() <= crow::LogLevel::Info) \
140 crow::logger("INFO ", crow::LogLevel::Info)
141#define CROW_LOG_DEBUG \
142 if (crow::logger::get_current_log_level() <= crow::LogLevel::Debug) \
143 crow::logger("DEBUG ", crow::LogLevel::Debug)